diff --git a/api/user.http.go b/api/user.http.go index 5cdd96c..4b468c7 100644 --- a/api/user.http.go +++ b/api/user.http.go @@ -1,16 +1,18 @@ package user import ( - "git.diulo.com/mogfee/kit/response" - "github.com/gin-gonic/gin" "context" "git.diulo.com/mogfee/kit/middleware" "git.diulo.com/mogfee/kit/errors" + "git.diulo.com/mogfee/kit/response" + "github.com/gin-gonic/gin" ) func RegisterUserHandler(app *gin.Engine, srv UserServer, m ...middleware.Middleware) { app.GET("/api/v1/user/list", httpListHandler(srv, m...)) app.GET("/api/v1/user/login", httpLoginHandler(srv, m...)) + app.GET("/api/v1/user/delete2", httpDelete2Handler(srv, m...)) + app.GET("/api/v1/user/delete3", httpDelete3Handler(srv, m...)) app.GET("/api/v1/user/delete", httpDeleteHandler(srv, m...)) app.GET("/api/v1/user/delete1", httpDelete1Handler(srv, m...)) } @@ -60,6 +62,52 @@ func httpLoginHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Co } } } +func httpDelete2Handler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) { + return func(c *gin.Context) { + var post LoginRequest + resp := response.New(c) + if err := resp.BindQuery(&post); err != nil { + resp.Error(err) + return + } + h := func(ctx context.Context, a any) (any, error) { + return srv.Delete2(ctx, a.(*LoginRequest)) + } + out, err := middleware.HttpMiddleware(c, h, m...)(c, &post) + if err != nil { + resp.Error(err) + } else { + if v, ok := out.(*LoginResponse); ok { + resp.Success(v) + } else { + resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse")) + } + } + } +} +func httpDelete3Handler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) { + return func(c *gin.Context) { + var post LoginRequest + resp := response.New(c) + if err := resp.BindQuery(&post); err != nil { + resp.Error(err) + return + } + h := func(ctx context.Context, a any) (any, error) { + return srv.Delete3(ctx, a.(*LoginRequest)) + } + out, err := middleware.HttpMiddleware(c, h, m...)(c, &post) + if err != nil { + resp.Error(err) + } else { + if v, ok := out.(*LoginResponse); ok { + resp.Success(v) + } else { + resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "LoginResponse")) + } + } + } +} func httpDeleteHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) { return func(c *gin.Context) { var post LoginRequest diff --git a/api/user.pb.go b/api/user.pb.go index d44f4c0..50968b5 100644 --- a/api/user.pb.go +++ b/api/user.pb.go @@ -157,7 +157,7 @@ var file_user_proto_rawDesc = []byte{ 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0x9c, 0x03, 0x0a, 0x04, 0x75, 0x73, + 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xea, 0x04, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x68, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, @@ -171,20 +171,33 @@ var file_user_proto_rawDesc = []byte{ 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0xc0, 0x45, 0x01, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x12, 0x12, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x12, - 0x63, 0x0a, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, - 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, - 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0xc0, 0x45, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12, - 0x13, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x12, 0x62, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x12, - 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, - 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, - 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, - 0x02, 0x16, 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, - 0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, 0x75, - 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x32, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, + 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0xc8, 0x45, 0x01, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, + 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x32, 0x12, 0x65, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x33, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, + 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, + 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0xc8, 0x45, + 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, + 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x33, 0x12, 0x63, 0x0a, + 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, + 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x1e, 0xc0, 0x45, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12, 0x13, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x12, 0x62, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x12, 0x1b, 0x2e, + 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, + 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, + 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, 0x75, 0x73, 0x65, + 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -207,14 +220,18 @@ var file_user_proto_goTypes = []interface{}{ var file_user_proto_depIdxs = []int32{ 0, // 0: com.diulo.api.user.list:input_type -> com.diulo.api.loginRequest 0, // 1: com.diulo.api.user.login:input_type -> com.diulo.api.loginRequest - 0, // 2: com.diulo.api.user.delete:input_type -> com.diulo.api.loginRequest - 0, // 3: com.diulo.api.user.delete1:input_type -> com.diulo.api.loginRequest - 1, // 4: com.diulo.api.user.list:output_type -> com.diulo.api.loginResponse - 1, // 5: com.diulo.api.user.login:output_type -> com.diulo.api.loginResponse - 1, // 6: com.diulo.api.user.delete:output_type -> com.diulo.api.loginResponse - 1, // 7: com.diulo.api.user.delete1:output_type -> com.diulo.api.loginResponse - 4, // [4:8] is the sub-list for method output_type - 0, // [0:4] is the sub-list for method input_type + 0, // 2: com.diulo.api.user.delete2:input_type -> com.diulo.api.loginRequest + 0, // 3: com.diulo.api.user.delete3:input_type -> com.diulo.api.loginRequest + 0, // 4: com.diulo.api.user.delete:input_type -> com.diulo.api.loginRequest + 0, // 5: com.diulo.api.user.delete1:input_type -> com.diulo.api.loginRequest + 1, // 6: com.diulo.api.user.list:output_type -> com.diulo.api.loginResponse + 1, // 7: com.diulo.api.user.login:output_type -> com.diulo.api.loginResponse + 1, // 8: com.diulo.api.user.delete2:output_type -> com.diulo.api.loginResponse + 1, // 9: com.diulo.api.user.delete3:output_type -> com.diulo.api.loginResponse + 1, // 10: com.diulo.api.user.delete:output_type -> com.diulo.api.loginResponse + 1, // 11: com.diulo.api.user.delete1:output_type -> com.diulo.api.loginResponse + 6, // [6:12] is the sub-list for method output_type + 0, // [0:6] 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 diff --git a/api/user.ts b/api/user.ts index 64e0253..066c638 100644 --- a/api/user.ts +++ b/api/user.ts @@ -29,6 +29,20 @@ export class userService{ method:'GET' }) } + static async delete2(data :loginRequest, param?: Config):Promise{ + return http('/api/v1/user/delete2', { + ...param, + data: data, + method:'GET' + }) + } + static async delete3(data :loginRequest, param?: Config):Promise{ + return http('/api/v1/user/delete3', { + ...param, + data: data, + method:'GET' + }) + } static async delete(data :loginRequest, param?: Config):Promise{ return http('/api/v1/user/delete', { ...param, diff --git a/api/user_grpc.pb.go b/api/user_grpc.pb.go index f0c30d7..0f13dcf 100644 --- a/api/user_grpc.pb.go +++ b/api/user_grpc.pb.go @@ -21,6 +21,8 @@ const _ = grpc.SupportPackageIsVersion7 const ( User_List_FullMethodName = "/com.diulo.api.user/list" User_Login_FullMethodName = "/com.diulo.api.user/login" + User_Delete2_FullMethodName = "/com.diulo.api.user/delete2" + User_Delete3_FullMethodName = "/com.diulo.api.user/delete3" User_Delete_FullMethodName = "/com.diulo.api.user/delete" User_Delete1_FullMethodName = "/com.diulo.api.user/delete1" ) @@ -33,6 +35,8 @@ type UserClient interface { List(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) // 等了 Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) + Delete2(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) + Delete3(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) Delete(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) Delete1(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) } @@ -63,6 +67,24 @@ func (c *userClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.C return out, nil } +func (c *userClient) Delete2(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { + out := new(LoginResponse) + err := c.cc.Invoke(ctx, User_Delete2_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *userClient) Delete3(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { + out := new(LoginResponse) + err := c.cc.Invoke(ctx, User_Delete3_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *userClient) Delete(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { out := new(LoginResponse) err := c.cc.Invoke(ctx, User_Delete_FullMethodName, in, out, opts...) @@ -89,6 +111,8 @@ type UserServer interface { List(context.Context, *LoginRequest) (*LoginResponse, error) // 等了 Login(context.Context, *LoginRequest) (*LoginResponse, error) + Delete2(context.Context, *LoginRequest) (*LoginResponse, error) + Delete3(context.Context, *LoginRequest) (*LoginResponse, error) Delete(context.Context, *LoginRequest) (*LoginResponse, error) Delete1(context.Context, *LoginRequest) (*LoginResponse, error) mustEmbedUnimplementedUserServer() @@ -104,6 +128,12 @@ func (UnimplementedUserServer) List(context.Context, *LoginRequest) (*LoginRespo func (UnimplementedUserServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") } +func (UnimplementedUserServer) Delete2(context.Context, *LoginRequest) (*LoginResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete2 not implemented") +} +func (UnimplementedUserServer) Delete3(context.Context, *LoginRequest) (*LoginResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete3 not implemented") +} func (UnimplementedUserServer) Delete(context.Context, *LoginRequest) (*LoginResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") } @@ -159,6 +189,42 @@ func _User_Login_Handler(srv interface{}, ctx context.Context, dec func(interfac return interceptor(ctx, in, info, handler) } +func _User_Delete2_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServer).Delete2(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: User_Delete2_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServer).Delete2(ctx, req.(*LoginRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _User_Delete3_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServer).Delete3(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: User_Delete3_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServer).Delete3(ctx, req.(*LoginRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _User_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(LoginRequest) if err := dec(in); err != nil { @@ -210,6 +276,14 @@ var User_ServiceDesc = grpc.ServiceDesc{ MethodName: "login", Handler: _User_Login_Handler, }, + { + MethodName: "delete2", + Handler: _User_Delete2_Handler, + }, + { + MethodName: "delete3", + Handler: _User_Delete3_Handler, + }, { MethodName: "delete", Handler: _User_Delete_Handler, diff --git a/api/user_http.pb.go b/api/user_http.pb.go index b9872bf..8f54480 100644 --- a/api/user_http.pb.go +++ b/api/user_http.pb.go @@ -9,6 +9,8 @@ import ( type UserHTTPServer interface { List(context.Context, *LoginRequest) (*LoginResponse, error) Login(context.Context, *LoginRequest) (*LoginResponse, error) + Delete2(context.Context, *LoginRequest) (*LoginResponse, error) + Delete3(context.Context, *LoginRequest) (*LoginResponse, error) Delete(context.Context, *LoginRequest) (*LoginResponse, error) Delete1(context.Context, *LoginRequest) (*LoginResponse, error) } @@ -17,6 +19,8 @@ func RegisterUserHTTPServer(s *http.Server, srv UserServer) { r := s.Route("/") r.GET("/api/v1/user/list", _User_List0_HTTP_Handler(srv)) r.GET("/api/v1/user/login", _User_Login0_HTTP_Handler(srv)) + r.GET("/api/v1/user/delete2", _User_Delete20_HTTP_Handler(srv)) + r.GET("/api/v1/user/delete3", _User_Delete30_HTTP_Handler(srv)) r.GET("/api/v1/user/delete", _User_Delete0_HTTP_Handler(srv)) r.GET("/api/v1/user/delete1", _User_Delete10_HTTP_Handler(srv)) } @@ -62,6 +66,45 @@ func _User_Login0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error return ctx.Result(200, reply) } } +func _User_Delete20_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in LoginRequest + var newCtx context.Context = ctx + newCtx = jwt.SetAutoAuthContext(newCtx, true) + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, "/com.diulo.api.user/delete2") + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.Delete2(ctx, req.(*LoginRequest)) + }) + out, err := h(newCtx, &in) + if err != nil { + return err + } + reply := out.(*LoginResponse) + return ctx.Result(200, reply) + } +} +func _User_Delete30_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error { + return func(ctx http.Context) error { + var in LoginRequest + var newCtx context.Context = ctx + if err := ctx.BindQuery(&in); err != nil { + return err + } + http.SetOperation(ctx, "/com.diulo.api.user/delete3") + h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.Delete3(ctx, req.(*LoginRequest)) + }) + out, err := h(newCtx, &in) + if err != nil { + return err + } + reply := out.(*LoginResponse) + return ctx.Result(200, reply) + } +} func _User_Delete0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error { return func(ctx http.Context) error { var in LoginRequest diff --git a/cmd/kit/main.go b/cmd/kit/main.go index 0115ef0..2594210 100644 --- a/cmd/kit/main.go +++ b/cmd/kit/main.go @@ -45,8 +45,8 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error { for _, s := range f.Services { addAuthKey := false for _, m := range s.Methods { - _, needAuth := protogen2.GetAuthKey(m) - if needAuth { + _, needAuth, autoAuth := protogen2.GetAuthKey(m) + if needAuth || autoAuth { addAuthKey = true } } @@ -99,7 +99,7 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error { } func (u *Kit) genGet(f *protogen.File, s *protogen.Service, t *protogen.GeneratedFile, m *protogen.Method) { - authKey, needAuth := protogen2.GetAuthKey(m) + authKey, needAuth, autoAuth := protogen2.GetAuthKey(m) method, path := protogen2.GetProtoMethod(m) if method == "" { return @@ -117,6 +117,10 @@ func (u *Kit) genGet(f *protogen.File, s *protogen.Service, t *protogen.Generate if needAuth { t.P(`newCtx = jwt.SetNeedAuthContext(newCtx, `, needAuth, `)`) } + if autoAuth { + t.P(`newCtx = jwt.SetAutoAuthContext(newCtx, `, autoAuth, `)`) + } + if method == protogen2.METHOD_GET { t.P(`if err := ctx.BindQuery(&in); err != nil { return err diff --git a/git.diulo.com/mogfee/kit/third_party/auth/auth.pb.go b/git.diulo.com/mogfee/kit/third_party/auth/auth.pb.go new file mode 100644 index 0000000..5496356 --- /dev/null +++ b/git.diulo.com/mogfee/kit/third_party/auth/auth.pb.go @@ -0,0 +1,127 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.17.3 +// source: third_party/auth/auth.proto + +package auth + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + descriptorpb "google.golang.org/protobuf/types/descriptorpb" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var file_third_party_auth_auth_proto_extTypes = []protoimpl.ExtensionInfo{ + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*string)(nil), + Field: 1111, + Name: "auth.auth_key", + Tag: "bytes,1111,opt,name=auth_key", + Filename: "third_party/auth/auth.proto", + }, + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*bool)(nil), + Field: 1112, + Name: "auth.auth", + Tag: "varint,1112,opt,name=auth", + Filename: "third_party/auth/auth.proto", + }, + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*bool)(nil), + Field: 1113, + Name: "auth.auto_auth", + Tag: "varint,1113,opt,name=auto_auth", + Filename: "third_party/auth/auth.proto", + }, +} + +// Extension fields to descriptorpb.MethodOptions. +var ( + // 权限|分割多个权限 + // + // optional string auth_key = 1111; + E_AuthKey = &file_third_party_auth_auth_proto_extTypes[0] + // 是否必须授权 + // + // optional bool auth = 1112; + E_Auth = &file_third_party_auth_auth_proto_extTypes[1] + // 可以不授权 + // + // optional bool auto_auth = 1113; + E_AutoAuth = &file_third_party_auth_auth_proto_extTypes[2] +) + +var File_third_party_auth_auth_proto protoreflect.FileDescriptor + +var file_third_party_auth_auth_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x74, 0x68, 0x69, 0x72, 0x64, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x79, 0x2f, 0x61, 0x75, + 0x74, 0x68, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x61, + 0x75, 0x74, 0x68, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3a, 0x3a, 0x0a, 0x08, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x6b, 0x65, + 0x79, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x18, 0xd7, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, 0x65, + 0x79, 0x3a, 0x33, 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd8, 0x08, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x3a, 0x3c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x61, + 0x75, 0x74, 0x68, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0xd9, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x75, 0x74, 0x6f, + 0x41, 0x75, 0x74, 0x68, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x2e, 0x64, 0x69, 0x75, 0x6c, + 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x6f, 0x67, 0x66, 0x65, 0x65, 0x2f, 0x6b, 0x69, 0x74, + 0x2f, 0x74, 0x68, 0x69, 0x72, 0x64, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x79, 0x2f, 0x61, 0x75, 0x74, + 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_third_party_auth_auth_proto_goTypes = []interface{}{ + (*descriptorpb.MethodOptions)(nil), // 0: google.protobuf.MethodOptions +} +var file_third_party_auth_auth_proto_depIdxs = []int32{ + 0, // 0: auth.auth_key:extendee -> google.protobuf.MethodOptions + 0, // 1: auth.auth:extendee -> google.protobuf.MethodOptions + 0, // 2: auth.auto_auth:extendee -> google.protobuf.MethodOptions + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 0, // [0:3] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_third_party_auth_auth_proto_init() } +func file_third_party_auth_auth_proto_init() { + if File_third_party_auth_auth_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_third_party_auth_auth_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 3, + NumServices: 0, + }, + GoTypes: file_third_party_auth_auth_proto_goTypes, + DependencyIndexes: file_third_party_auth_auth_proto_depIdxs, + ExtensionInfos: file_third_party_auth_auth_proto_extTypes, + }.Build() + File_third_party_auth_auth_proto = out.File + file_third_party_auth_auth_proto_rawDesc = nil + file_third_party_auth_auth_proto_goTypes = nil + file_third_party_auth_auth_proto_depIdxs = nil +} diff --git a/middleware/jwt/jwt.go b/middleware/jwt/jwt.go index 66ef61c..b2949ad 100644 --- a/middleware/jwt/jwt.go +++ b/middleware/jwt/jwt.go @@ -138,3 +138,17 @@ func FromNeedAuthContext(ctx context.Context) bool { } return v.(bool) } + +type autoAuthKey struct { +} + +func SetAutoAuthContext(ctx context.Context, autoAuth bool) context.Context { + return context.WithValue(ctx, autoAuthKey{}, autoAuth) +} +func FromAutoAuthContext(ctx context.Context) bool { + v := ctx.Value(autoAuthKey{}) + if v == nil { + return false + } + return v.(bool) +} diff --git a/proto/user.proto b/proto/user.proto index 540efae..04eae30 100644 --- a/proto/user.proto +++ b/proto/user.proto @@ -24,6 +24,20 @@ service user{ get: "/api/v1/user/login", }; } + + rpc delete2(loginRequest)returns(loginResponse){ + option(auth.auto_auth) = true; + option (google.api.http) = { + get: "/api/v1/user/delete2", + }; + } + + rpc delete3(loginRequest)returns(loginResponse){ + option(auth.auto_auth) = false; + option (google.api.http) = { + get: "/api/v1/user/delete3", + }; + } rpc delete(loginRequest)returns(loginResponse){ option(auth.auth) = false; option (google.api.http) = { diff --git a/protogen/protogen.go b/protogen/protogen.go index 92833e0..c913e50 100644 --- a/protogen/protogen.go +++ b/protogen/protogen.go @@ -33,11 +33,11 @@ func GetProtoMethod(m *protogen.Method) (method string, path string) { return "", "" } -func GetAuthKey(m *protogen.Method) (authKey string, needAuth bool) { +func GetAuthKey(m *protogen.Method) (authKey string, needAuth bool, autoAuth bool) { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if opts, err := proto.GetExtension(op, auth.E_AuthKey); err == nil { if vv := opts.(*string); ok && *vv != "" { - return *vv, true + return *vv, true, false } } } @@ -45,9 +45,17 @@ func GetAuthKey(m *protogen.Method) (authKey string, needAuth bool) { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if opts, err := proto.GetExtension(op, auth.E_Auth); err == nil { if v, ok := opts.(*bool); ok && *v { - return "", true + return "", true, false } } } - return "", false + + if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { + if opts, err := proto.GetExtension(op, auth.E_AutoAuth); err == nil { + if v, ok := opts.(*bool); ok && *v { + return "", false, true + } + } + } + return "", false, false }