refactor: localize protobuf definitions
This commit is contained in:
@@ -4,16 +4,10 @@ package server
|
||||
import (
|
||||
pb "bsm/full/module/base/feedback/pb"
|
||||
"context"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -27,7 +21,6 @@ func New(addr string) *Server {
|
||||
srv := &Server{
|
||||
Ctx: context.Background(),
|
||||
Grpc: grpc.NewServer(),
|
||||
Mux: gwRuntime.NewServeMux(gwRuntime.WithForwardResponseRewriter(responseEnvelope)),
|
||||
grpcConns: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
|
||||
@@ -36,56 +29,5 @@ func New(addr string) *Server {
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 连接池: 只创建一次连接并复用
|
||||
conn, ok := srv.grpcConns[addr]
|
||||
if !ok {
|
||||
var err error
|
||||
conn, err = grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic("failed to dial grpc server: " + err.Error())
|
||||
}
|
||||
srv.grpcConns[addr] = conn
|
||||
}
|
||||
|
||||
// 将服务注册到Gateway
|
||||
|
||||
if err := pb.RegisterMethodHandler(srv.Ctx, srv.Mux, conn); err != nil {
|
||||
panic("Failed to register Method handler: " + err.Error())
|
||||
}
|
||||
|
||||
// Register services swagger
|
||||
srv.RegisterSwagger()
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
// RegisterSwagger 注册swagger
|
||||
func (s *Server) RegisterSwagger() {
|
||||
srvKey := strings.ToLower(vars.ServiceKey)
|
||||
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(bytes)
|
||||
return
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// response envelope
|
||||
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
|
||||
name := string(response.ProtoReflect().Descriptor().Name())
|
||||
if name == "Status" || name == "Error" || name == "StatusReply" {
|
||||
return response, nil
|
||||
}
|
||||
return map[string]any{
|
||||
"code": 0,
|
||||
"message": vars.OK,
|
||||
"details": response,
|
||||
"timeseq": time.Now().Unix(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
3238
module/base/feedback/pb/const.pb.go
Normal file
3238
module/base/feedback/pb/const.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
316
module/base/feedback/proto/const.proto
Normal file
316
module/base/feedback/proto/const.proto
Normal file
@@ -0,0 +1,316 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package blocks;
|
||||
|
||||
option go_package = "bsm/full/module/base/feedback/pb;feedback";
|
||||
|
||||
// Shared request and response messages.
|
||||
message Empty {}
|
||||
|
||||
message FetchRequest {
|
||||
int64 page_no = 1 [json_name = "page_no"];
|
||||
int64 page_size = 2 [json_name = "page_size"];
|
||||
map<string, string> params = 3;
|
||||
}
|
||||
|
||||
|
||||
message VersionRequest {
|
||||
int64 version = 1;
|
||||
}
|
||||
|
||||
message SearchRequest {
|
||||
string keyword = 1;
|
||||
}
|
||||
|
||||
|
||||
// Service-specific variants whose wire formats differ from the shared types.
|
||||
message CmsSearchRequest {
|
||||
string keyword = 1;
|
||||
int64 page_no = 2 [json_name = "page_no"];
|
||||
int64 page_size = 3 [json_name = "page_size"];
|
||||
}
|
||||
|
||||
message MallFetchRequest {
|
||||
int64 page_no = 1 [json_name = "page_no"];
|
||||
int64 page_size = 2 [json_name = "page_size"];
|
||||
map<string, string> params = 3;
|
||||
string store_identity = 4 [json_name = "store_identity"];
|
||||
string keyword = 5;
|
||||
repeated int64 category_id = 6;
|
||||
string sort = 7;
|
||||
int64 min_price = 8 [json_name = "min_price"];
|
||||
int64 max_price = 9 [json_name = "max_price"];
|
||||
}
|
||||
|
||||
message MarketFetchRequest {
|
||||
int64 page_no = 1 [json_name = "page_no"];
|
||||
int64 page_size = 2 [json_name = "page_size"];
|
||||
map<string, string> params = 3;
|
||||
string identity = 4;
|
||||
string keyword = 5;
|
||||
int32 status = 6;
|
||||
int32 approve = 7;
|
||||
}
|
||||
|
||||
message OrderIdentRequest {
|
||||
int64 id = 1;
|
||||
string identity = 2;
|
||||
string reason = 3;
|
||||
int32 approve = 4;
|
||||
string agency = 5;
|
||||
string store_identity = 6;
|
||||
}
|
||||
|
||||
message DeliveryStatusReply {
|
||||
int64 status = 1;
|
||||
string identity = 2;
|
||||
string message = 3;
|
||||
int64 timeseq = 4;
|
||||
}
|
||||
|
||||
message IdentityStatusReply {
|
||||
int32 code = 1;
|
||||
string identity = 2;
|
||||
string message = 3;
|
||||
int64 timeseq = 4;
|
||||
}
|
||||
|
||||
message OrderStatusReply {
|
||||
int32 code = 1;
|
||||
string identity = 2;
|
||||
string message = 3;
|
||||
int64 timeseq = 4;
|
||||
string reason = 5;
|
||||
}
|
||||
|
||||
message DataStatusReply {
|
||||
string data = 1;
|
||||
int64 timeseq = 2;
|
||||
}
|
||||
|
||||
message StoreSerialRequest {
|
||||
string store_identity = 1 [json_name = "store_identity"];
|
||||
repeated string serial_id = 2 [json_name = "serial_id"];
|
||||
}
|
||||
|
||||
// Cloud messages.
|
||||
message IDRequest {
|
||||
uint64 id = 1;
|
||||
}
|
||||
|
||||
message IDListRequest {
|
||||
repeated uint64 ids = 1;
|
||||
}
|
||||
|
||||
message StdIicuds {
|
||||
uint64 id = 1;
|
||||
string created_at = 2;
|
||||
string updated_at = 3;
|
||||
string deleted_at = 4;
|
||||
}
|
||||
|
||||
message StdPassport {
|
||||
uint64 passport_id = 1;
|
||||
string passport_identity = 2;
|
||||
}
|
||||
|
||||
message CloudBase {
|
||||
uint64 cloud_id = 1;
|
||||
string cloud_identity = 2;
|
||||
}
|
||||
|
||||
// CMS messages.
|
||||
message CmsCategoryItem {
|
||||
string site_identity = 1 [json_name = "site_identity"];
|
||||
int64 id = 2;
|
||||
string identity = 3;
|
||||
int64 parent_id = 4 [json_name = "parent_id"];
|
||||
string title = 5;
|
||||
string cover_path = 6 [json_name = "cover_path"];
|
||||
string intro = 7;
|
||||
string created_at = 8 [json_name = "created_at"];
|
||||
string updated_at = 9 [json_name = "updated_at"];
|
||||
repeated CmsCategoryItem child = 10;
|
||||
string category_key = 11 [json_name = "category_key"];
|
||||
}
|
||||
|
||||
message CmsTagsItem {
|
||||
int64 id = 1;
|
||||
string identity = 2;
|
||||
string title = 3;
|
||||
string cover_path = 4 [json_name = "cover_path"];
|
||||
string intro = 5;
|
||||
string created_at = 6 [json_name = "created_at"];
|
||||
}
|
||||
|
||||
message CmsAccessoryItem {
|
||||
string identity = 1;
|
||||
string title = 2;
|
||||
string file_path = 3 [json_name = "file_path"];
|
||||
string created_at = 4 [json_name = "created_at"];
|
||||
}
|
||||
|
||||
// Passport messages.
|
||||
message VerifyStatus {
|
||||
int32 email_verify = 1;
|
||||
int32 phone_verify = 2;
|
||||
int32 face_verify = 3;
|
||||
int32 document_verify = 4;
|
||||
int32 kyc_verify = 5;
|
||||
}
|
||||
|
||||
// Market messages.
|
||||
message MarketLoginReply {
|
||||
string token = 1;
|
||||
string identity = 2;
|
||||
string market_identity = 3 [json_name = "market_identity"];
|
||||
string name = 4;
|
||||
string account = 5;
|
||||
string role = 6;
|
||||
int32 status = 7;
|
||||
string created_at = 8 [json_name = "created_at"];
|
||||
string market_name = 9 [json_name = "market_name"];
|
||||
}
|
||||
|
||||
// Order messages.
|
||||
message OrderSummaryItem {
|
||||
int64 id = 1;
|
||||
string order_no = 2 [json_name = "order_no"];
|
||||
int64 partner_id = 3 [json_name = "partner_id"];
|
||||
string identity = 4;
|
||||
int64 total_price = 7 [json_name = "total_price"];
|
||||
int64 trans_price = 8 [json_name = "trans_price"];
|
||||
int64 refund_price = 9 [json_name = "refund_price"];
|
||||
int64 logistics_fee = 11 [json_name = "logistics_fee"];
|
||||
int64 coupon_amount = 12 [json_name = "coupon_amount"];
|
||||
string remark = 13;
|
||||
int32 status = 14;
|
||||
string logistics_number = 15 [json_name = "logistics_number"];
|
||||
string address_identity = 16 [json_name = "address_identity"];
|
||||
string county = 17;
|
||||
string province = 18;
|
||||
string city = 19;
|
||||
string area = 20;
|
||||
string address = 21;
|
||||
string contact = 22;
|
||||
string phone = 23;
|
||||
string delivery_time = 24 [json_name = "delivery_time"];
|
||||
string delivery_identity = 25 [json_name = "delivery_identity"];
|
||||
int32 pay_type = 26 [json_name = "pay_type"];
|
||||
int64 pay_amount = 27 [json_name = "pay_amount"];
|
||||
string pay_trade_no = 28 [json_name = "pay_trade_no"];
|
||||
string pay_time = 29 [json_name = "pay_time"];
|
||||
string pay_remark = 30 [json_name = "pay_remark"];
|
||||
string created = 31;
|
||||
string updated = 32;
|
||||
repeated OrderDetails details = 33;
|
||||
string addr = 34;
|
||||
string car_identity = 35 [json_name = "car_identity"];
|
||||
string delivery_address = 36 [json_name = "delivery_address"];
|
||||
string brand = 37;
|
||||
string version = 38;
|
||||
string license_number = 39 [json_name = "license_number"];
|
||||
string member_name = 40 [json_name = "member_name"];
|
||||
string member_phone = 41 [json_name = "member_phone"];
|
||||
int32 approve = 42;
|
||||
}
|
||||
|
||||
message OrderDetails {
|
||||
int64 id = 1;
|
||||
int64 product_id = 2 [json_name = "product_id"];
|
||||
string spec_no = 3 [json_name = "spec_no"];
|
||||
string spec = 4;
|
||||
int64 type = 5;
|
||||
string title = 6;
|
||||
string cover_image = 7 [json_name = "cover_image"];
|
||||
int64 sales_price = 8 [json_name = "sales_price"];
|
||||
string product_args = 9 [json_name = "product_args"];
|
||||
int64 number = 10;
|
||||
int64 unit_price = 11 [json_name = "unit_price"];
|
||||
int64 spec_id = 12 [json_name = "spec_id"];
|
||||
string product_identity = 13 [json_name = "product_identity"];
|
||||
int64 gas_types = 14 [json_name = "gas_types"];
|
||||
int64 total_price = 15 [json_name = "total_price"];
|
||||
}
|
||||
|
||||
// Social feed messages.
|
||||
message FeedPostListReply {
|
||||
repeated FeedPostItem list = 1;
|
||||
int64 cnt = 2;
|
||||
}
|
||||
|
||||
message FeedPostItem {
|
||||
string identity = 1;
|
||||
string content = 2;
|
||||
int64 feed_id = 3;
|
||||
string feed_identity = 4;
|
||||
bool is_open = 5;
|
||||
int64 cnt_unlike = 6;
|
||||
int64 cnt_comment = 7;
|
||||
int64 cnt_like = 8;
|
||||
repeated FeedAttachItem attachs = 9;
|
||||
repeated FeedTagItem tags = 10;
|
||||
}
|
||||
|
||||
message FeedAttachItem {
|
||||
string identity = 1;
|
||||
string attach_type = 2;
|
||||
string url = 3;
|
||||
}
|
||||
|
||||
message FeedTagItem {
|
||||
string key = 1;
|
||||
string content = 2;
|
||||
}
|
||||
|
||||
// Social group messages.
|
||||
message GroupPostListReply {
|
||||
repeated GroupPostItem list = 1;
|
||||
int64 cnt = 2;
|
||||
}
|
||||
|
||||
message GroupPostItem {
|
||||
string identity = 1;
|
||||
string content = 2;
|
||||
int64 passport_id = 3;
|
||||
string passport_identity = 4;
|
||||
bool is_open = 5;
|
||||
int64 cnt_unlike = 6;
|
||||
int64 cnt_comment = 7;
|
||||
int64 cnt_like = 8;
|
||||
repeated GroupAttachItem attachs = 9;
|
||||
repeated GroupTagItem tags = 10;
|
||||
}
|
||||
|
||||
message GroupAttachItem {
|
||||
string identity = 1;
|
||||
string attach_type = 2;
|
||||
string url = 3;
|
||||
}
|
||||
|
||||
message GroupTagItem {
|
||||
string key = 1;
|
||||
string content = 2;
|
||||
}
|
||||
|
||||
// Social relation messages.
|
||||
message RelationItem {
|
||||
string identity = 1;
|
||||
string nickname = 2;
|
||||
string remark_name = 3;
|
||||
int32 popular = 4;
|
||||
string avatar = 5;
|
||||
string birthday = 6;
|
||||
int32 sex = 7;
|
||||
int32 province = 8;
|
||||
int32 city = 9;
|
||||
int32 area = 10;
|
||||
string sign = 11;
|
||||
repeated string tags = 12;
|
||||
int32 foreign_status = 13;
|
||||
}
|
||||
|
||||
message FetchRelationItemReply {
|
||||
int64 total = 1;
|
||||
repeated RelationItem data = 2;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
# 微服务相关配置
|
||||
service:
|
||||
key: feedback
|
||||
origin: bsm
|
||||
describe: system feedback microservice
|
||||
|
||||
# 编译选项:二进制文件,docker镜像
|
||||
build:
|
||||
- binary
|
||||
- docker
|
||||
|
||||
|
||||
# docker 环境镜像
|
||||
docker_image: golang:1.26.5
|
||||
|
||||
# docker 私有仓库
|
||||
docker_registry:
|
||||
endpoint: cid.apinb.com
|
||||
account: op
|
||||
password: 123456
|
||||
|
||||
# 微服务系统变量,docker或宿主机
|
||||
start:
|
||||
- export BlocksMesh_Workspace=scf
|
||||
- export BlocksMesh_Prefix=/usr/local/bsm/
|
||||
- export BlocksMesh_RuntimeMode=dev
|
||||
- export BlocksMesh_JwtSecretKey=Cblocksmesh2022C
|
||||
@@ -1,32 +0,0 @@
|
||||
filebeat.inputs:
|
||||
- type: log
|
||||
enabled: true
|
||||
# 开启json解析
|
||||
json.keys_under_root: true
|
||||
json.add_error_key: true
|
||||
# 日志文件路径
|
||||
paths:
|
||||
- ./logs/feedback/error.log
|
||||
- ./logs/feedback/slow.log
|
||||
|
||||
setup.template.settings:
|
||||
index.number_of_shards: 1
|
||||
|
||||
# 定义kafka topic field
|
||||
fields:
|
||||
log_topic: scf.feedback.dev
|
||||
|
||||
# 输出到kafka
|
||||
output.kafka:
|
||||
hosts: ["127.0.0.1:9092"]
|
||||
topic: '%{[fields.log_topic]}'
|
||||
partition.round_robin:
|
||||
reachable_only: false
|
||||
required_acks: 1
|
||||
keep_alive: 10s
|
||||
|
||||
# ================================= Processors =================================
|
||||
processors:
|
||||
- decode_json_fields:
|
||||
fields: ['@timestamp','level','content','trace','span','duration']
|
||||
target: ""
|
||||
@@ -1,5 +0,0 @@
|
||||
#install
|
||||
go install github.com/securego/gosec/v2/cmd/gosec@latest
|
||||
|
||||
#run
|
||||
gosec -fmt=json -out=./test/lint/gosec.json ./...
|
||||
@@ -1,216 +0,0 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "feedback.proto",
|
||||
"version": "version not set"
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"name": "Method"
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {},
|
||||
"definitions": {
|
||||
"feedbackAddReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"identity": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackFeedbackAccessory": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"identity": {
|
||||
"type": "string"
|
||||
},
|
||||
"item_identity": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"title": "附件标题"
|
||||
},
|
||||
"file_path": {
|
||||
"type": "string",
|
||||
"title": "附件地址"
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackFeedbackImage": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"identity": {
|
||||
"type": "string"
|
||||
},
|
||||
"itemIdentity": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackFeedbackItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"identity": {
|
||||
"type": "string"
|
||||
},
|
||||
"user_identity": {
|
||||
"type": "string",
|
||||
"title": "用户唯一标识"
|
||||
},
|
||||
"user_name": {
|
||||
"type": "string",
|
||||
"title": "用户名称"
|
||||
},
|
||||
"status": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "状态,1未处理,2已处理,也可以调用方自行设置,如果未设置则默认是1"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string",
|
||||
"title": "创建时间"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string",
|
||||
"title": "更新时间"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"title": "标题"
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"title": "内容"
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/feedbackFeedbackImage"
|
||||
},
|
||||
"title": "图片"
|
||||
},
|
||||
"remark": {
|
||||
"type": "string",
|
||||
"title": "反馈信息"
|
||||
},
|
||||
"category": {
|
||||
"type": "string",
|
||||
"title": "类型: 1:pre_sales 2:after_sales"
|
||||
},
|
||||
"accessories": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/feedbackFeedbackAccessory"
|
||||
}
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"title": "邮箱"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string",
|
||||
"title": "手机号码"
|
||||
},
|
||||
"store_identity": {
|
||||
"type": "string",
|
||||
"title": "店铺标识"
|
||||
},
|
||||
"agency": {
|
||||
"type": "string",
|
||||
"title": "代理"
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackGetReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"record": {
|
||||
"$ref": "#/definitions/feedbackFeedbackItem"
|
||||
},
|
||||
"exists": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackListReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"count": {
|
||||
"type": "string",
|
||||
"format": "int64"
|
||||
},
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/feedbackFeedbackItem"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"feedbackStatusReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"title": "状态码"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"title": "状态说明"
|
||||
},
|
||||
"details": {
|
||||
"type": "string",
|
||||
"title": "数据"
|
||||
},
|
||||
"timeseq": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"title": "响应时间序列"
|
||||
}
|
||||
}
|
||||
},
|
||||
"protobufAny": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"@type": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"rpcStatus": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/protobufAny"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user