Merge branch 'master' of ssh://gitlab.fusenpack.com/backend/proto
This commit is contained in:
commit
e8083abe94
0
.idea/.gitignore
vendored
Normal file
0
.idea/.gitignore
vendored
Normal file
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/proto.iml" filepath="$PROJECT_DIR$/.idea/proto.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
9
.idea/proto.iml
Normal file
9
.idea/proto.iml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
31
.idea/workspace.xml
Normal file
31
.idea/workspace.xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b5794a41-9642-4323-96b1-af915a69a610" name="Default Changelist" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="GOROOT" url="file://$USER_HOME$/go/go1.20.5" />
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2Z4eaM0G8nB9gvBxbH1CbcT3s8N" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="go.import.settings.migrated" value="true" />
|
||||
<property name="go.sdk.automatically.set" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
17
README.md
17
README.md
|
@ -3,11 +3,24 @@
|
|||
#### 介绍
|
||||
公共协议, 每个服务需要git submodule 拉 xxx/proto 目录下. 然后使用序列.
|
||||
|
||||
```
|
||||
安装protoc protoc-25.0-linux-x86_64.zip
|
||||
```
|
||||
|
||||
```bash
|
||||
git submodule add https://gitee.com/fusenpack/proto
|
||||
# 去掉SUMDB的验证
|
||||
go env -w GOSUMDB="off"
|
||||
|
||||
git submodule add git@gitlab.fusenpack.com:backend/proto.git
|
||||
```
|
||||
然后执行
|
||||
```bash
|
||||
go install \
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
|
||||
google.golang.org/protobuf/cmd/protoc-gen-go \
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
||||
|
||||
go run proto/goutils/proto_build/main.go
|
||||
或者
|
||||
在proto/goutils/proto_build/main_test.go执行测试 TestMain
|
||||
|
@ -15,6 +28,8 @@ go run proto/goutils/proto_build/main.go
|
|||
./update_fspkg_master.sh # 执行更新最新的包
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
|
|
@ -267,6 +267,12 @@ func ExecCreateAutoLogic(workerSpaceDir string, ServiceName string, genDir, pack
|
|||
// 处理main.go文件
|
||||
defer func() {
|
||||
// name := underscoreToLowerCamelCase(ServiceName)
|
||||
|
||||
// name := underscoreToLowerCamelCase(ServiceName)
|
||||
createFile("server/main_gen.go", func(f io.Writer) error {
|
||||
return tpl.ExecuteTemplate(f, "main_gen.tpl", mtpl)
|
||||
})
|
||||
|
||||
createFileWithPermNotExists("server/main.go", func(f io.Writer) error {
|
||||
return tpl.ExecuteTemplate(f, "main.tpl", mtpl)
|
||||
})
|
||||
|
@ -1265,6 +1271,34 @@ func _getTypeString(expr ast.Expr, packageName *string, level int) string {
|
|||
}
|
||||
}
|
||||
|
||||
func createFile(filename string, do func(f io.Writer) error) error {
|
||||
// 检测文件是否存在
|
||||
|
||||
file, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var buf = bytes.NewBuffer(nil)
|
||||
err = do(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
_, err = file.Write(buf.Bytes())
|
||||
} else {
|
||||
_, err = file.Write(data)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createFileWithPermNotExists(filename string, do func(f io.Writer) error) error {
|
||||
// 检测文件是否存在
|
||||
_, err := os.Stat(filename)
|
||||
|
|
|
@ -30,9 +30,8 @@ func main() {
|
|||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
s := grpc.NewServer(sopt) //新建一个grpc服务
|
||||
{{range .StructServiceNames}}
|
||||
service.Register{{.StructServiceName}}Server(s, &{{.LogicPackageName}}.{{.StructServiceName}}LogicGrpc{}) // {{.LogicPackageName}} 服务注册
|
||||
{{- end}}
|
||||
|
||||
MainRegisterServer(s) // 注册所有的service
|
||||
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
|
|
16
goutils/proto_build/tpls/main_gen.tpl
Normal file
16
goutils/proto_build/tpls/main_gen.tpl
Normal file
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"{{.ProjectName}}/gen/go/service"
|
||||
{{range .StructServiceNames}}
|
||||
"{{$.ProjectName}}/server/logics/{{.LogicPackageName}}"
|
||||
{{- end}}
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func MainRegisterServer(s *grpc.Server) {
|
||||
{{range .StructServiceNames}}
|
||||
service.Register{{.StructServiceName}}Server(s, &{{.LogicPackageName}}.{{.StructServiceName}}LogicGrpc{}) // {{.LogicPackageName}} 服务注册
|
||||
{{- end}}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
syntax = "proto3"; //版本声明,使用v3版本
|
||||
|
||||
package fsservice;
|
||||
option go_package = "gitlab.fusenpack.com/backend/service;service";
|
||||
|
||||
option go_package = "gitee.com/fusenpack/fusen-service;service";
|
||||
|
||||
// 导入google/api/annotations.proto 注释依赖
|
||||
import "google/api/annotations.proto";
|
||||
import "service/basic.proto";
|
||||
|
@ -11,7 +11,7 @@ import "google/protobuf/any.proto";
|
|||
|
||||
|
||||
//定义服务
|
||||
service info {
|
||||
service info {
|
||||
// 用户信息
|
||||
rpc UserInfo(UserInfoRequest) returns (basic.Response) {
|
||||
option (google.api.http) = {
|
||||
|
@ -124,6 +124,21 @@ service info {
|
|||
|
||||
}
|
||||
|
||||
//定义产品服务
|
||||
service product {
|
||||
// 产品详情
|
||||
rpc GetProductDetail(GetProductDetailReq) returns (basic.Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/product/get_product_detail"
|
||||
};
|
||||
}
|
||||
//获取产品列表
|
||||
rpc GetProductList(GetProductListReq) returns (basic.Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/product/tag_product_list"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
message UserInfoRequest {
|
||||
repeated string module = 1; // 模块
|
||||
|
@ -134,7 +149,7 @@ message QueryProfileRequest {
|
|||
}
|
||||
|
||||
message QueryProfileResponse {
|
||||
google.protobuf.Struct data = 1;
|
||||
google.protobuf.Struct data = 1;
|
||||
}
|
||||
|
||||
message DefaultProfileRequest {
|
||||
|
@ -213,4 +228,17 @@ message ContactUsRequest {
|
|||
string message = 4; // 消息内容
|
||||
}
|
||||
|
||||
|
||||
//获取产品详情
|
||||
message GetProductDetailReq{
|
||||
int64 product_id = 1;
|
||||
string template_tag = 2;
|
||||
int64 selected_color_index = 3;
|
||||
string logo = 4;
|
||||
}
|
||||
//获取产品列表
|
||||
message GetProductListReq{
|
||||
int64 basic_tag_id = 1; //传入则以该分类为最高层分类查询
|
||||
int64 merchant_type = 2; //商户类型
|
||||
string template_tag = 3; //模板标签
|
||||
bool with_product = 4; //是否携带分类下的产品
|
||||
}
|
59
service/resource.proto
Normal file
59
service/resource.proto
Normal file
|
@ -0,0 +1,59 @@
|
|||
syntax = "proto3"; //版本声明,使用v3版本
|
||||
|
||||
package resource;
|
||||
option go_package = "gitlab.fusenpack.com/backend/resource;service";
|
||||
|
||||
// 导入google/api/annotations.proto 注释依赖
|
||||
import "google/api/annotations.proto";
|
||||
import "service/basic.proto";
|
||||
import "google/protobuf/struct.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
//定义服务
|
||||
service resource {
|
||||
|
||||
// 获取资源详情
|
||||
rpc GetResourceInfo(GetResourceInfoReq) returns (basic.Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/resource/info"
|
||||
};
|
||||
}
|
||||
|
||||
// 获取资源列表
|
||||
rpc GetResourceList(GetResourceListReq) returns (basic.Response) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/resource/list"
|
||||
};
|
||||
}
|
||||
}
|
||||
/* 获取资源列表 */
|
||||
message GetResourceListReq{
|
||||
optional string resource_id = 1;
|
||||
optional int64 guest_id =2;
|
||||
optional int64 user_id =3;
|
||||
optional string resource_type = 4;
|
||||
optional string resource_url = 5;
|
||||
optional string version = 6;
|
||||
optional int64 api_type = 7;
|
||||
optional string bucket_name = 8;
|
||||
optional string source = 9;
|
||||
|
||||
optional int64 current_page =101;
|
||||
optional int64 per_page =102;
|
||||
optional string order_by = 103;
|
||||
}
|
||||
/* 获取资源列表 */
|
||||
|
||||
/* 获取资源详情 */
|
||||
message GetResourceInfoReq{
|
||||
optional string resource_id = 1;
|
||||
optional int64 guest_id =2;
|
||||
optional int64 user_id =3;
|
||||
optional string resource_type = 4;
|
||||
optional string resource_url = 5;
|
||||
optional string version = 6;
|
||||
optional int64 api_type = 7;
|
||||
optional string bucket_name = 8;
|
||||
optional string source = 9;
|
||||
}
|
||||
/* 获取资源详情 */
|
Loading…
Reference in New Issue
Block a user