deving
This commit is contained in:
commit
b179e22f93
|
@ -0,0 +1,13 @@
|
||||||
|
module git.apinb.com/bsm-tools/protoc-gen-test-http
|
||||||
|
|
||||||
|
go 1.24.6
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.apinb.com/bsm-sdk/core v0.0.65
|
||||||
|
google.golang.org/protobuf v1.36.8
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/oklog/ulid/v2 v2.1.0 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,13 @@
|
||||||
|
git.apinb.com/bsm-sdk/core v0.0.65 h1:mUgX3X6W1Lz4Keh5K6/XGVLc1EcY7AX2xBw6srKQT2g=
|
||||||
|
git.apinb.com/bsm-sdk/core v0.0.65/go.mod h1:FY2knuEVN7d7eHhpkyI+Cj/4oJ34gqZ8xzE7hB3JkOE=
|
||||||
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
|
||||||
|
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
|
||||||
|
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||||
|
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
|
@ -0,0 +1,79 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"git.apinb.com/bsm-sdk/core/utils"
|
||||||
|
"google.golang.org/protobuf/compiler/protogen"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flags flag.FlagSet
|
||||||
|
path = flags.String("path", "", "输出目录,默认为当前目录")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
opts := protogen.Options{
|
||||||
|
ParamFunc: func(name, value string) error {
|
||||||
|
//fmt.Println(name, value)
|
||||||
|
flags.Set(name, value)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.Run(func(gen *protogen.Plugin) error {
|
||||||
|
// set output directory
|
||||||
|
if *path == "" {
|
||||||
|
*path, _ = os.Getwd()
|
||||||
|
*path = filepath.Join(*path, "test/http")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !utils.PathExists(*path) {
|
||||||
|
os.MkdirAll(*path, 0755)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range gen.Files {
|
||||||
|
if len(file.Services) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := generateFiles(gen, file); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateFiles(gen *protogen.Plugin, file *protogen.File) error {
|
||||||
|
for _, service := range file.Services {
|
||||||
|
for _, method := range service.Methods {
|
||||||
|
sm := fmt.Sprintf("==> %s.%s", service.GoName, method.GoName)
|
||||||
|
// 生成测试文件
|
||||||
|
if err := generateHttpTestFile(gen, file, service, method); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(sm) // 打印服务和方法名
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateHttpTestFile(gen *protogen.Plugin, file *protogen.File, service *protogen.Service, method *protogen.Method) error {
|
||||||
|
filename := fmt.Sprintf("%s_%s_test.json", service.GoName, method.GoName)
|
||||||
|
g := gen.NewGeneratedFile(filepath.Join(*path, filename), "")
|
||||||
|
g.P("{")
|
||||||
|
g.P(` "name": "` + method.GoName + `",`)
|
||||||
|
g.P(` "url": "http://localhost:8080/` + service.GoName + `/` + method.GoName + `",`)
|
||||||
|
g.P(` "method": "POST",`)
|
||||||
|
g.P(` "headers": {`)
|
||||||
|
g.P(` "Content-Type": "application/json"`)
|
||||||
|
g.P(` },`)
|
||||||
|
g.P(` "body": {`)
|
||||||
|
g.P(` }`)
|
||||||
|
g.P("}")
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package initial;
|
||||||
|
option go_package = ".;initial";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// initial-检测是否有新版或新的配置
|
||||||
|
service Check{
|
||||||
|
|
||||||
|
// HELLO
|
||||||
|
rpc Hello(Crc) returns (StatusReply){}
|
||||||
|
|
||||||
|
// 检查更新
|
||||||
|
rpc Updates(CheckForUpdatesRequest) returns (CheckForUpdatesReply) {}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message Crc{
|
||||||
|
string code = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message StatusReply{
|
||||||
|
int64 status = 1; // 状态码
|
||||||
|
string identity=2; // 标识码
|
||||||
|
string message=3; //状态说明
|
||||||
|
int64 timeseq=4; // 响应时间序列
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
message CheckForUpdatesRequest {
|
||||||
|
string app = 1; // 应用程序名称 <必填>
|
||||||
|
string os = 2; // 操作系统 <必填>
|
||||||
|
string arch = 3; // 构架名称 <必填>
|
||||||
|
string version = 4; // 版本号 <必填>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message CheckForUpdatesReply {
|
||||||
|
string identity = 1; // 唯一码
|
||||||
|
string version = 2; // 版本号
|
||||||
|
string summary = 3; // 更析说明
|
||||||
|
string files = 4; // 更新文件以及文件hash
|
||||||
|
string pubdate =5; // 发布时间
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package initial;
|
||||||
|
option go_package = ".;initial";
|
||||||
|
|
||||||
|
|
||||||
|
// initial-数据
|
||||||
|
service Data{
|
||||||
|
|
||||||
|
// 获取应用的相关配置信息
|
||||||
|
rpc Config(ConfigRequest) returns (ConfigReply) {}
|
||||||
|
|
||||||
|
// 系统区域数据,默认级别:市
|
||||||
|
rpc Areas(AreasRequest) returns (AreasReply) {}
|
||||||
|
|
||||||
|
// 系统标签数据
|
||||||
|
rpc Tags(Empty) returns (TagsReply) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message Empty{
|
||||||
|
}
|
||||||
|
|
||||||
|
message AreasRequest {
|
||||||
|
bool show_town=1; // 是否输出乡镇,默认:市级
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfigRequest {
|
||||||
|
string app = 1; // 应用程序名称 <必填>
|
||||||
|
string os = 2; // 操作系统 <必填>
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfigReply {
|
||||||
|
repeated ConfigItem data=1; // 配置参数列表
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfigItem {
|
||||||
|
string Identity=1; //唯一标识
|
||||||
|
string key=2; //配置键
|
||||||
|
string value=3; //配置值
|
||||||
|
int64 version=4; //版本号
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message AreasReply {
|
||||||
|
repeated AreasItem areas=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AreasItem {
|
||||||
|
string id =1;
|
||||||
|
string pid=2;
|
||||||
|
int32 deep=3;
|
||||||
|
string name=4;
|
||||||
|
string pinyin_prefix=5;
|
||||||
|
string pinyin=6;
|
||||||
|
string ext_id=7;
|
||||||
|
string ext_name=8;
|
||||||
|
}
|
||||||
|
message TagsReply {
|
||||||
|
repeated TagsItem tags=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TagsItem {
|
||||||
|
int64 id =1;
|
||||||
|
int32 type=2;
|
||||||
|
string key=3;
|
||||||
|
string title=4;
|
||||||
|
string remark=5;
|
||||||
|
string icon=6;
|
||||||
|
}
|
Loading…
Reference in New Issue