feat : script service
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-01-23 14:48:44 +08:00
parent ab78141e7d
commit b3c49eaa34
17 changed files with 485 additions and 84 deletions
+7 -4
View File
@@ -12,11 +12,14 @@ import (
"time"
)
func GetContextDB(ctx context.Context, db *gorm.DB) (*gorm.DB, error) {
if err := db.Use(&TracePlugin{}); err != nil {
return nil, err
func init() {
if err := DB.Use(&TracePlugin{}); err != nil {
panic(err)
}
return db.WithContext(ctx), nil
}
func GetContextDB(ctx context.Context) (*gorm.DB, error) {
return DB.WithContext(ctx), nil
}
type SQL struct {
+16 -6
View File
@@ -201,6 +201,7 @@ type Scripts struct {
unknownFields protoimpl.UnknownFields
Scripts []*Script `protobuf:"bytes,1,rep,name=scripts,proto3" json:"scripts,omitempty"`
Total int64 `protobuf:"zigzag64,2,opt,name=total,proto3" json:"total,omitempty"`
}
func (x *Scripts) Reset() {
@@ -242,6 +243,13 @@ func (x *Scripts) GetScripts() []*Script {
return nil
}
func (x *Scripts) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
var File_script_proto protoreflect.FileDescriptor
var file_script_proto_rawDesc = []byte{
@@ -288,15 +296,17 @@ var file_script_proto_rawDesc = []byte{
0x52, 0x12, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x78, 0x53,
0x63, 0x6f, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x69, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x71, 0x69, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x69, 0x73, 0x5f, 0x64, 0x65, 0x6c,
0x18, 0x11, 0x20, 0x01, 0x28, 0x12, 0x52, 0x05, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x22, 0x33, 0x0a,
0x18, 0x11, 0x20, 0x01, 0x28, 0x12, 0x52, 0x05, 0x69, 0x73, 0x44, 0x65, 0x6c, 0x22, 0x49, 0x0a,
0x07, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12, 0x28, 0x0a, 0x07, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x2e, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x52, 0x07, 0x73, 0x63, 0x72, 0x69, 0x70,
0x74, 0x73, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65,
0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61,
0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x74, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28,
0x12, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x2e,
0x69, 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72,
0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72,
0x64, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
@@ -24,4 +24,5 @@ message Script {
message Scripts {
repeated Script scripts = 1;
sint64 total = 2;
}
+42 -42
View File
@@ -8,6 +8,7 @@ package murders
import (
script "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script"
tag "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/tag"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
@@ -26,9 +27,9 @@ type QueryCondition struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Page *int64 `protobuf:"zigzag64,1,opt,name=page,proto3,oneof" json:"page,omitempty"`
Size *int64 `protobuf:"zigzag64,2,opt,name=size,proto3,oneof" json:"size,omitempty"`
QueryMap map[string]string `protobuf:"bytes,3,rep,name=query_map,json=queryMap,proto3" json:"query_map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
Page *int64 `protobuf:"zigzag64,1,opt,name=page,proto3,oneof" json:"page,omitempty"`
Size *int64 `protobuf:"zigzag64,2,opt,name=size,proto3,oneof" json:"size,omitempty"`
Query *string `protobuf:"bytes,3,opt,name=query,proto3,oneof" json:"query,omitempty"`
}
func (x *QueryCondition) Reset() {
@@ -77,11 +78,11 @@ func (x *QueryCondition) GetSize() int64 {
return 0
}
func (x *QueryCondition) GetQueryMap() map[string]string {
if x != nil {
return x.QueryMap
func (x *QueryCondition) GetQuery() string {
if x != nil && x.Query != nil {
return *x.Query
}
return nil
return ""
}
var File_service_proto protoreflect.FileDescriptor
@@ -89,29 +90,27 @@ var File_service_proto protoreflect.FileDescriptor
var file_service_proto_rawDesc = []byte{
0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x06, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x1a, 0x13, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2f,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x01, 0x0a,
0x0e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12,
0x17, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x12, 0x48, 0x00, 0x52,
0x04, 0x70, 0x61, 0x67, 0x65, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x12, 0x48, 0x01, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x88, 0x01,
0x01, 0x12, 0x41, 0x0a, 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51, 0x75,
0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x51, 0x75, 0x65,
0x72, 0x79, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x71, 0x75, 0x65, 0x72,
0x79, 0x4d, 0x61, 0x70, 0x1a, 0x3b, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x4d, 0x61, 0x70,
0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x73,
0x69, 0x7a, 0x65, 0x32, 0x42, 0x0a, 0x07, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x73, 0x12, 0x37,
0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12, 0x16, 0x2e, 0x6d,
0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69,
0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x0f, 0x2e, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x53, 0x63,
0x72, 0x69, 0x70, 0x74, 0x73, 0x22, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x2e, 0x69,
0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f, 0x72, 0x65,
0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75, 0x72, 0x64,
0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0d, 0x74, 0x61,
0x67, 0x2f, 0x74, 0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x79, 0x0a, 0x0e, 0x51,
0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a,
0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x12, 0x48, 0x00, 0x52, 0x04, 0x70,
0x61, 0x67, 0x65, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x12, 0x48, 0x01, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12,
0x19, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02,
0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x70,
0x61, 0x67, 0x65, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x08, 0x0a, 0x06,
0x5f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x32, 0x71, 0x0a, 0x07, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72,
0x73, 0x12, 0x37, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x12,
0x16, 0x2e, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x43, 0x6f,
0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x0f, 0x2e, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x2e, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x22, 0x00, 0x12, 0x2d, 0x0a, 0x07, 0x47, 0x65,
0x74, 0x54, 0x61, 0x67, 0x73, 0x12, 0x16, 0x2e, 0x6d, 0x75, 0x72, 0x64, 0x65, 0x72, 0x2e, 0x51,
0x75, 0x65, 0x72, 0x79, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x08, 0x2e,
0x74, 0x61, 0x67, 0x2e, 0x54, 0x61, 0x67, 0x22, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74,
0x2e, 0x69, 0x63, 0x65, 0x63, 0x68, 0x65, 0x6e, 0x2e, 0x63, 0x6e, 0x2f, 0x6d, 0x6f, 0x6e, 0x6f,
0x72, 0x65, 0x70, 0x6f, 0x2f, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2f, 0x70, 0x6b, 0x67,
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x72, 0x61, 0x68, 0x6d, 0x61, 0x2f, 0x6d, 0x75,
0x72, 0x64, 0x65, 0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -126,21 +125,22 @@ func file_service_proto_rawDescGZIP() []byte {
return file_service_proto_rawDescData
}
var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_service_proto_goTypes = []interface{}{
(*QueryCondition)(nil), // 0: murder.QueryCondition
nil, // 1: murder.QueryCondition.QueryMapEntry
(*script.Scripts)(nil), // 2: script.Scripts
(*script.Scripts)(nil), // 1: script.Scripts
(*tag.Tag)(nil), // 2: tag.Tag
}
var file_service_proto_depIdxs = []int32{
1, // 0: murder.QueryCondition.query_map:type_name -> murder.QueryCondition.QueryMapEntry
0, // 1: murder.murders.GetScripts:input_type -> murder.QueryCondition
2, // 2: murder.murders.GetScripts:output_type -> script.Scripts
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
0, // 0: murder.murders.GetScripts:input_type -> murder.QueryCondition
0, // 1: murder.murders.GetTags:input_type -> murder.QueryCondition
1, // 2: murder.murders.GetScripts:output_type -> script.Scripts
2, // 3: murder.murders.GetTags:output_type -> tag.Tag
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_service_proto_init() }
@@ -169,7 +169,7 @@ func file_service_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_service_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumMessages: 1,
NumExtensions: 0,
NumServices: 1,
},
+3 -1
View File
@@ -1,14 +1,16 @@
syntax = "proto3";
import "script/script.proto";
import "tag/tag.proto";
option go_package = "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders";
package murder;
service murders{
rpc GetScripts(QueryCondition) returns(script.Scripts){}
rpc GetTags(QueryCondition) returns(tag.Tag){}
}
message QueryCondition {
optional sint64 page = 1;
optional sint64 size = 2;
map<string, string> query_map = 3;
optional string query =3;
}
@@ -9,6 +9,7 @@ package murders
import (
context "context"
script "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/script"
tag "git.icechen.cn/monorepo/backend/pkg/proto/brahma/murders/tag"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@@ -24,6 +25,7 @@ const _ = grpc.SupportPackageIsVersion7
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type MurdersClient interface {
GetScripts(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*script.Scripts, error)
GetTags(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*tag.Tag, error)
}
type murdersClient struct {
@@ -43,11 +45,21 @@ func (c *murdersClient) GetScripts(ctx context.Context, in *QueryCondition, opts
return out, nil
}
func (c *murdersClient) GetTags(ctx context.Context, in *QueryCondition, opts ...grpc.CallOption) (*tag.Tag, error) {
out := new(tag.Tag)
err := c.cc.Invoke(ctx, "/murder.murders/GetTags", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// MurdersServer is the server API for Murders service.
// All implementations must embed UnimplementedMurdersServer
// for forward compatibility
type MurdersServer interface {
GetScripts(context.Context, *QueryCondition) (*script.Scripts, error)
GetTags(context.Context, *QueryCondition) (*tag.Tag, error)
mustEmbedUnimplementedMurdersServer()
}
@@ -58,6 +70,9 @@ type UnimplementedMurdersServer struct {
func (UnimplementedMurdersServer) GetScripts(context.Context, *QueryCondition) (*script.Scripts, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetScripts not implemented")
}
func (UnimplementedMurdersServer) GetTags(context.Context, *QueryCondition) (*tag.Tag, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetTags not implemented")
}
func (UnimplementedMurdersServer) mustEmbedUnimplementedMurdersServer() {}
// UnsafeMurdersServer may be embedded to opt out of forward compatibility for this service.
@@ -89,6 +104,24 @@ func _Murders_GetScripts_Handler(srv interface{}, ctx context.Context, dec func(
return interceptor(ctx, in, info, handler)
}
func _Murders_GetTags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(QueryCondition)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MurdersServer).GetTags(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/murder.murders/GetTags",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MurdersServer).GetTags(ctx, req.(*QueryCondition))
}
return interceptor(ctx, in, info, handler)
}
// Murders_ServiceDesc is the grpc.ServiceDesc for Murders service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -100,6 +133,10 @@ var Murders_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetScripts",
Handler: _Murders_GetScripts_Handler,
},
{
MethodName: "GetTags",
Handler: _Murders_GetTags_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "service.proto",
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"git.icechen.cn/monorepo/backend/pkg/env"
_ "git.icechen.cn/monorepo/backend/pkg/orm"
"github.com/gofiber/fiber/v2"
ctxLogger "github.com/luizsuper/ctxLoggers"
"go.uber.org/zap"
@@ -31,7 +32,7 @@ func Interceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInf
if err != nil {
ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s", info.FullMethod)), zap.Float64("cost_time", costSeconds), zap.String("errorReason", err.Error()))
} else {
ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s, %v", info.FullMethod, resp)), zap.Float64("cost_time", costSeconds), zap.Any("resp", resp))
//ctxLogger.Debug(ctx, serverName, zap.String("gRPC method", fmt.Sprintf(" %s, %v", info.FullMethod, resp)), zap.Float64("cost_time", costSeconds), zap.Any("resp", resp))
}
return resp, err
}