李伟乐 1 year ago
parent 0d7c8bd362
commit 15856dad19
  1. 52
      api/user.http.go
  2. 63
      api/user.pb.go
  3. 14
      api/user.ts
  4. 74
      api/user_grpc.pb.go
  5. 43
      api/user_http.pb.go
  6. 10
      cmd/kit/main.go
  7. 127
      git.diulo.com/mogfee/kit/third_party/auth/auth.pb.go
  8. 14
      middleware/jwt/jwt.go
  9. 14
      proto/user.proto
  10. 16
      protogen/protogen.go

@ -1,16 +1,18 @@
package user package user
import ( import (
"git.diulo.com/mogfee/kit/response"
"github.com/gin-gonic/gin"
"context" "context"
"git.diulo.com/mogfee/kit/middleware" "git.diulo.com/mogfee/kit/middleware"
"git.diulo.com/mogfee/kit/errors" "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) { func RegisterUserHandler(app *gin.Engine, srv UserServer, m ...middleware.Middleware) {
app.GET("/api/v1/user/list", httpListHandler(srv, m...)) app.GET("/api/v1/user/list", httpListHandler(srv, m...))
app.GET("/api/v1/user/login", httpLoginHandler(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/delete", httpDeleteHandler(srv, m...))
app.GET("/api/v1/user/delete1", httpDelete1Handler(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) { func httpDeleteHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Context) {
return func(c *gin.Context) { return func(c *gin.Context) {
var post LoginRequest var post LoginRequest

@ -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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 0x65, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x32, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d,
0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69,
0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0xc0, 0x45, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0xc8, 0x45, 0x01, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16,
0x13, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64,
0x6c, 0x65, 0x74, 0x65, 0x12, 0x62, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x12, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x32, 0x12, 0x65, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65,
0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x33, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70,
0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c,
0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c, 0x6f, 0x67, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x6c,
0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0xc8, 0x45,
0x02, 0x16, 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x00, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x12, 0x14, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31,
0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x31, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, 0x75, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x33, 0x12, 0x63, 0x0a,
0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@ -207,14 +220,18 @@ var file_user_proto_goTypes = []interface{}{
var file_user_proto_depIdxs = []int32{ var file_user_proto_depIdxs = []int32{
0, // 0: com.diulo.api.user.list:input_type -> com.diulo.api.loginRequest 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, // 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, // 2: com.diulo.api.user.delete2:input_type -> com.diulo.api.loginRequest
0, // 3: com.diulo.api.user.delete1:input_type -> com.diulo.api.loginRequest 0, // 3: com.diulo.api.user.delete3:input_type -> com.diulo.api.loginRequest
1, // 4: com.diulo.api.user.list:output_type -> com.diulo.api.loginResponse 0, // 4: com.diulo.api.user.delete:input_type -> com.diulo.api.loginRequest
1, // 5: com.diulo.api.user.login:output_type -> com.diulo.api.loginResponse 0, // 5: com.diulo.api.user.delete1:input_type -> com.diulo.api.loginRequest
1, // 6: com.diulo.api.user.delete:output_type -> com.diulo.api.loginResponse 1, // 6: com.diulo.api.user.list:output_type -> com.diulo.api.loginResponse
1, // 7: com.diulo.api.user.delete1:output_type -> com.diulo.api.loginResponse 1, // 7: com.diulo.api.user.login:output_type -> com.diulo.api.loginResponse
4, // [4:8] is the sub-list for method output_type 1, // 8: com.diulo.api.user.delete2:output_type -> com.diulo.api.loginResponse
0, // [0:4] is the sub-list for method input_type 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 type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name

@ -29,6 +29,20 @@ export class userService{
method:'GET' method:'GET'
}) })
} }
static async delete2(data :loginRequest, param?: Config<loginRequest>):Promise<loginResponse>{
return http<loginRequest, loginResponse>('/api/v1/user/delete2', {
...param,
data: data,
method:'GET'
})
}
static async delete3(data :loginRequest, param?: Config<loginRequest>):Promise<loginResponse>{
return http<loginRequest, loginResponse>('/api/v1/user/delete3', {
...param,
data: data,
method:'GET'
})
}
static async delete(data :loginRequest, param?: Config<loginRequest>):Promise<loginResponse>{ static async delete(data :loginRequest, param?: Config<loginRequest>):Promise<loginResponse>{
return http<loginRequest, loginResponse>('/api/v1/user/delete', { return http<loginRequest, loginResponse>('/api/v1/user/delete', {
...param, ...param,

@ -21,6 +21,8 @@ const _ = grpc.SupportPackageIsVersion7
const ( const (
User_List_FullMethodName = "/com.diulo.api.user/list" User_List_FullMethodName = "/com.diulo.api.user/list"
User_Login_FullMethodName = "/com.diulo.api.user/login" 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_Delete_FullMethodName = "/com.diulo.api.user/delete"
User_Delete1_FullMethodName = "/com.diulo.api.user/delete1" 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) List(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error)
// 等了 // 等了
Login(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) Delete(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error)
Delete1(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 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) { func (c *userClient) Delete(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
out := new(LoginResponse) out := new(LoginResponse)
err := c.cc.Invoke(ctx, User_Delete_FullMethodName, in, out, opts...) err := c.cc.Invoke(ctx, User_Delete_FullMethodName, in, out, opts...)
@ -89,6 +111,8 @@ type UserServer interface {
List(context.Context, *LoginRequest) (*LoginResponse, error) List(context.Context, *LoginRequest) (*LoginResponse, error)
// 等了 // 等了
Login(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) Delete(context.Context, *LoginRequest) (*LoginResponse, error)
Delete1(context.Context, *LoginRequest) (*LoginResponse, error) Delete1(context.Context, *LoginRequest) (*LoginResponse, error)
mustEmbedUnimplementedUserServer() mustEmbedUnimplementedUserServer()
@ -104,6 +128,12 @@ func (UnimplementedUserServer) List(context.Context, *LoginRequest) (*LoginRespo
func (UnimplementedUserServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) { func (UnimplementedUserServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") 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) { func (UnimplementedUserServer) Delete(context.Context, *LoginRequest) (*LoginResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") 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) 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) { func _User_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginRequest) in := new(LoginRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
@ -210,6 +276,14 @@ var User_ServiceDesc = grpc.ServiceDesc{
MethodName: "login", MethodName: "login",
Handler: _User_Login_Handler, Handler: _User_Login_Handler,
}, },
{
MethodName: "delete2",
Handler: _User_Delete2_Handler,
},
{
MethodName: "delete3",
Handler: _User_Delete3_Handler,
},
{ {
MethodName: "delete", MethodName: "delete",
Handler: _User_Delete_Handler, Handler: _User_Delete_Handler,

@ -9,6 +9,8 @@ import (
type UserHTTPServer interface { type UserHTTPServer interface {
List(context.Context, *LoginRequest) (*LoginResponse, error) List(context.Context, *LoginRequest) (*LoginResponse, error)
Login(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) Delete(context.Context, *LoginRequest) (*LoginResponse, error)
Delete1(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 := s.Route("/")
r.GET("/api/v1/user/list", _User_List0_HTTP_Handler(srv)) 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/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/delete", _User_Delete0_HTTP_Handler(srv))
r.GET("/api/v1/user/delete1", _User_Delete10_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) 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 { func _User_Delete0_HTTP_Handler(srv UserHTTPServer) func(ctx http.Context) error {
return func(ctx http.Context) error { return func(ctx http.Context) error {
var in LoginRequest var in LoginRequest

@ -45,8 +45,8 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error {
for _, s := range f.Services { for _, s := range f.Services {
addAuthKey := false addAuthKey := false
for _, m := range s.Methods { for _, m := range s.Methods {
_, needAuth := protogen2.GetAuthKey(m) _, needAuth, autoAuth := protogen2.GetAuthKey(m)
if needAuth { if needAuth || autoAuth {
addAuthKey = true 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) { 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) method, path := protogen2.GetProtoMethod(m)
if method == "" { if method == "" {
return return
@ -117,6 +117,10 @@ func (u *Kit) genGet(f *protogen.File, s *protogen.Service, t *protogen.Generate
if needAuth { if needAuth {
t.P(`newCtx = jwt.SetNeedAuthContext(newCtx, `, needAuth, `)`) t.P(`newCtx = jwt.SetNeedAuthContext(newCtx, `, needAuth, `)`)
} }
if autoAuth {
t.P(`newCtx = jwt.SetAutoAuthContext(newCtx, `, autoAuth, `)`)
}
if method == protogen2.METHOD_GET { if method == protogen2.METHOD_GET {
t.P(`if err := ctx.BindQuery(&in); err != nil { t.P(`if err := ctx.BindQuery(&in); err != nil {
return err return err

@ -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
}

@ -138,3 +138,17 @@ func FromNeedAuthContext(ctx context.Context) bool {
} }
return v.(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)
}

@ -24,6 +24,20 @@ service user{
get: "/api/v1/user/login", 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){ rpc delete(loginRequest)returns(loginResponse){
option(auth.auth) = false; option(auth.auth) = false;
option (google.api.http) = { option (google.api.http) = {

@ -33,11 +33,11 @@ func GetProtoMethod(m *protogen.Method) (method string, path string) {
return "", "" 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 op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok {
if opts, err := proto.GetExtension(op, auth.E_AuthKey); err == nil { if opts, err := proto.GetExtension(op, auth.E_AuthKey); err == nil {
if vv := opts.(*string); ok && *vv != "" { 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 op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok {
if opts, err := proto.GetExtension(op, auth.E_Auth); err == nil { if opts, err := proto.GetExtension(op, auth.E_Auth); err == nil {
if v, ok := opts.(*bool); ok && *v { 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
} }

Loading…
Cancel
Save