master
李伟乐 2 years ago
parent 43203c2223
commit 448c20617f
  1. 65
      main.go
  2. 5
      proto/auth/auth.proto
  3. 5
      proto/user.proto
  4. 46
      proto/v1/auth/auth.pb.go
  5. 4
      proto/v1/auth/auth.pb.validate.go
  6. 26
      proto/v1/user.gin.go
  7. 61
      proto/v1/user.pb.go
  8. 3
      run/main.go
  9. 2
      service/service.go

@ -1,7 +1,6 @@
package main package main
import ( import (
"git.echinacities.com/mogfee/protoc-gen-kit/proto/v1/auth"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/compiler/protogen"
@ -35,7 +34,6 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error {
if len(f.Services) == 0 { if len(f.Services) == 0 {
continue continue
} }
//log.Println(f.Desc.Name())
fname := f.GeneratedFilenamePrefix + ".gin.go" fname := f.GeneratedFilenamePrefix + ".gin.go"
t := plugin.NewGeneratedFile(fname, f.GoImportPath) t := plugin.NewGeneratedFile(fname, f.GoImportPath)
t.P("package " + f.Desc.Name()) t.P("package " + f.Desc.Name())
@ -47,20 +45,14 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error {
t.P(`func NewGin(app *gin.Engine,srv UserServer) {`) t.P(`func NewGin(app *gin.Engine,srv UserServer) {`)
for _, s := range f.Services { for _, s := range f.Services {
//t.P(`app.GET("/", func(c *gin.Context) {c.String(200, "ok")})`)
for _, m := range s.Methods { for _, m := range s.Methods {
method, path := u.getMethod(m) method, path := u.getMethod(m)
t.P(`_http_`, method, `_`, m.GoName, `(app, "`, path, `", srv)`) t.P(`app.`, method, `("`, path, `",http`, m.GoName, `(srv))`)
} }
} }
t.P(`}`) t.P(`}`)
for _, s := range f.Services { for _, s := range f.Services {
log.Println(s.GoName)
//t.P(`app.GET("/", func(c *gin.Context) {c.String(200, "ok")})`)
for _, m := range s.Methods { for _, m := range s.Methods {
method, _ := u.getMethod(m) method, _ := u.getMethod(m)
switch method { switch method {
case method_get: case method_get:
@ -71,22 +63,15 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error {
u.genDelete(t, m) u.genDelete(t, m)
} }
//log.Println(m.Desc.Options().ProtoReflect().Get(annotations.E_Http).List())
//log.Println(m.Input.GoIdent.GoName)
//log.Println(m.Input.Desc.Name())
//log.Println(m.Output.Desc.Name())
} }
} }
} }
return nil return nil
} }
func (Kit) genGet(t *protogen.GeneratedFile, m *protogen.Method) { func (u *Kit) genGet(t *protogen.GeneratedFile, m *protogen.Method) {
t.P("func _http_", method_get, `_`, m.GoName, "(router *gin.Engine, method string, srv UserServer){") t.P("func http", m.GoName, "(srv UserServer)func(c *gin.Context){")
t.P(`router.`, method_get, `(method, func(c *gin.Context) { t.P(`return func(c *gin.Context) {
post := `, m.Input.GoIdent.GoName, `{} post := `, m.Input.GoIdent.GoName, `{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindQuery(&post); err != nil { if err := resp.BindQuery(&post); err != nil {
@ -99,12 +84,12 @@ func (Kit) genGet(t *protogen.GeneratedFile, m *protogen.Method) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
})`) }`)
t.P("}") t.P("}")
} }
func (Kit) genPost(t *protogen.GeneratedFile, m *protogen.Method) { func (u *Kit) genPost(t *protogen.GeneratedFile, m *protogen.Method) {
t.P("func _http_", method_post, `_`, m.GoName, "(router *gin.Engine, method string, srv UserServer){") t.P("func http", m.GoName, "(srv UserServer)func(c *gin.Context){")
t.P(`router.`, method_post, `(method, func(c *gin.Context) { t.P(`return func(c *gin.Context) {
post := `, m.Input.GoIdent.GoName, `{} post := `, m.Input.GoIdent.GoName, `{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindJSON(&post); err != nil { if err := resp.BindJSON(&post); err != nil {
@ -117,12 +102,12 @@ func (Kit) genPost(t *protogen.GeneratedFile, m *protogen.Method) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
})`) }`)
t.P("}") t.P("}")
} }
func (Kit) genDelete(t *protogen.GeneratedFile, m *protogen.Method) { func (u *Kit) genDelete(t *protogen.GeneratedFile, m *protogen.Method) {
t.P("func _http_", method_delete, `_`, m.GoName, "(router *gin.Engine, method string, srv UserServer){") t.P("func http", m.GoName, "(srv UserServer)func(c *gin.Context){")
t.P(`router.`, method_delete, `(method, func(c *gin.Context) { t.P(`return func(c *gin.Context) {
post := `, m.Input.GoIdent.GoName, `{} post := `, m.Input.GoIdent.GoName, `{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindJSON(&post); err != nil { if err := resp.BindJSON(&post); err != nil {
@ -135,22 +120,22 @@ func (Kit) genDelete(t *protogen.GeneratedFile, m *protogen.Method) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
})`) }`)
t.P("}") t.P("}")
} }
func (Kit) getAuth(m *protogen.Method) (bool, string) { //func (Kit) getAuth(m *protogen.Method) *auth.AuthInfo {
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 {
log.Println(err) // log.Println(err)
} else { // } else {
if vv, ok := opts.(*auth.AuthInfo); ok { // if vv, ok := opts.(*auth.AuthInfo); ok {
return vv.Auth, vv.AuthKey // return vv
} // }
} // }
} // }
return false, "" // return &auth.AuthInfo{}
} //}
func (Kit) getMethod(m *protogen.Method) (method string, path string) { func (Kit) getMethod(m *protogen.Method) (method string, path string) {
if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok {
if opts, err := proto.GetExtension(op, annotations.E_Http); err != nil { if opts, err := proto.GetExtension(op, annotations.E_Http); err != nil {

@ -9,6 +9,7 @@ extend google.protobuf.MethodOptions{
} }
message AuthInfo { message AuthInfo {
bool auth = 1; bool auto_auth = 1;
string auth_key = 2; bool must_auth = 2;
string auth_key = 3;
} }

@ -7,7 +7,6 @@ import "validate/validate.proto";
import "google/api/annotations.proto"; import "google/api/annotations.proto";
import "google/protobuf/descriptor.proto"; import "google/protobuf/descriptor.proto";
import "auth/auth.proto";
service user{ service user{
rpc list(loginRequest)returns(loginResponse){ rpc list(loginRequest)returns(loginResponse){
@ -26,10 +25,6 @@ service user{
delete: "/api/v1/user/delete", delete: "/api/v1/user/delete",
body:"*" body:"*"
}; };
option(auth.auth) = {
auth:true,
auth_key:"11",
};
} }
} }
message loginRequest{ message loginRequest{

@ -26,8 +26,9 @@ type AuthInfo struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Auth bool `protobuf:"varint,1,opt,name=auth,proto3" json:"auth,omitempty"` AutoAuth bool `protobuf:"varint,1,opt,name=auto_auth,json=autoAuth,proto3" json:"auto_auth,omitempty"`
AuthKey string `protobuf:"bytes,2,opt,name=auth_key,json=authKey,proto3" json:"auth_key,omitempty"` MustAuth bool `protobuf:"varint,2,opt,name=must_auth,json=mustAuth,proto3" json:"must_auth,omitempty"`
AuthKey string `protobuf:"bytes,3,opt,name=auth_key,json=authKey,proto3" json:"auth_key,omitempty"`
} }
func (x *AuthInfo) Reset() { func (x *AuthInfo) Reset() {
@ -62,9 +63,16 @@ func (*AuthInfo) Descriptor() ([]byte, []int) {
return file_auth_auth_proto_rawDescGZIP(), []int{0} return file_auth_auth_proto_rawDescGZIP(), []int{0}
} }
func (x *AuthInfo) GetAuth() bool { func (x *AuthInfo) GetAutoAuth() bool {
if x != nil { if x != nil {
return x.Auth return x.AutoAuth
}
return false
}
func (x *AuthInfo) GetMustAuth() bool {
if x != nil {
return x.MustAuth
} }
return false return false
} }
@ -99,20 +107,22 @@ var file_auth_auth_proto_rawDesc = []byte{
0x0a, 0x0f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x0a, 0x0f, 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, 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, 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, 0x22, 0x39, 0x0a, 0x08, 0x41, 0x75, 0x74, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, 0x08, 0x41, 0x75, 0x74,
0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x18, 0x01, 0x20, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x61, 0x75,
0x01, 0x28, 0x08, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x12, 0x19, 0x0a, 0x08, 0x61, 0x75, 0x74, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x75, 0x74, 0x6f, 0x41, 0x75,
0x68, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x75, 0x74, 0x74, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x75, 0x73, 0x74, 0x5f, 0x61, 0x75, 0x74, 0x68, 0x18,
0x68, 0x4b, 0x65, 0x79, 0x3a, 0x43, 0x0a, 0x04, 0x61, 0x75, 0x74, 0x68, 0x12, 0x1e, 0x2e, 0x67, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6d, 0x75, 0x73, 0x74, 0x41, 0x75, 0x74, 0x68, 0x12,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x19, 0x0a, 0x08, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28,
0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd7, 0x08, 0x20, 0x09, 0x52, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x3a, 0x43, 0x0a, 0x04, 0x61, 0x75,
0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x49, 0x74, 0x68, 0x12, 0x1e, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6e, 0x66, 0x6f, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x2e, 0x65, 0x63, 0x68, 0x69, 0x6e, 0x61, 0x63, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x18, 0xd7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x75, 0x74, 0x68,
0x6d, 0x2f, 0x6d, 0x6f, 0x67, 0x66, 0x65, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x42,
0x67, 0x65, 0x6e, 0x2d, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x31, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x2e, 0x65, 0x63, 0x68, 0x69, 0x6e, 0x61, 0x63, 0x69, 0x74,
0x2f, 0x61, 0x75, 0x74, 0x68, 0x3b, 0x61, 0x75, 0x74, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x6f, 0x67, 0x66, 0x65, 0x65, 0x2f, 0x70,
0x6f, 0x33, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x3b, 0x61, 0x75, 0x74, 0x68,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

@ -57,7 +57,9 @@ func (m *AuthInfo) validate(all bool) error {
var errors []error var errors []error
// no validation rules for Auth // no validation rules for AutoAuth
// no validation rules for MustAuth
// no validation rules for AuthKey // no validation rules for AuthKey

@ -1,17 +1,17 @@
package user package user
import ( import (
"git.echinacities.com/mogfee/protoc-gen-kit/response"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/mogfee/protoc-gen-kit/response"
) )
func NewGin(app *gin.Engine, srv UserServer) { func NewGin(app *gin.Engine, srv UserServer) {
_http_GET_List(app, "/api/v1/user/list", srv) app.GET("/api/v1/user/list", httpList(srv))
_http_POST_Login(app, "/api/v1/user/login", srv) app.POST("/api/v1/user/login", httpLogin(srv))
_http_DELETE_Delete(app, "/api/v1/user/delete", srv) app.DELETE("/api/v1/user/delete", httpDelete(srv))
} }
func _http_GET_List(router *gin.Engine, method string, srv UserServer) { func httpList(srv UserServer) func(c *gin.Context) {
router.GET(method, func(c *gin.Context) { return func(c *gin.Context) {
post := LoginRequest{} post := LoginRequest{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindQuery(&post); err != nil { if err := resp.BindQuery(&post); err != nil {
@ -24,10 +24,10 @@ func _http_GET_List(router *gin.Engine, method string, srv UserServer) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
}) }
} }
func _http_POST_Login(router *gin.Engine, method string, srv UserServer) { func httpLogin(srv UserServer) func(c *gin.Context) {
router.POST(method, func(c *gin.Context) { return func(c *gin.Context) {
post := LoginRequest{} post := LoginRequest{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindJSON(&post); err != nil { if err := resp.BindJSON(&post); err != nil {
@ -40,10 +40,10 @@ func _http_POST_Login(router *gin.Engine, method string, srv UserServer) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
}) }
} }
func _http_DELETE_Delete(router *gin.Engine, method string, srv UserServer) { func httpDelete(srv UserServer) func(c *gin.Context) {
router.DELETE(method, func(c *gin.Context) { return func(c *gin.Context) {
post := LoginRequest{} post := LoginRequest{}
resp := response.New(c) resp := response.New(c)
if err := resp.BindJSON(&post); err != nil { if err := resp.BindJSON(&post); err != nil {
@ -56,5 +56,5 @@ func _http_DELETE_Delete(router *gin.Engine, method string, srv UserServer) {
return return
} }
c.JSON(200, result) c.JSON(200, result)
}) }
} }

@ -7,7 +7,6 @@
package user package user
import ( import (
_ "git.echinacities.com/mogfee/protoc-gen-kit/proto/v1/auth"
_ "github.com/envoyproxy/protoc-gen-validate/validate" _ "github.com/envoyproxy/protoc-gen-validate/validate"
_ "google.golang.org/genproto/googleapis/api/annotations" _ "google.golang.org/genproto/googleapis/api/annotations"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
@ -144,40 +143,38 @@ var file_user_proto_rawDesc = []byte{
0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f,
0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x75, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7b, 0x0a, 0x0c, 0x6c, 0x6f, 0x67, 0x69, 0x6e,
0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7b, 0x0a, 0x0c, 0x6c, 0x6f, 0x67, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e,
0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x10, 0x04, 0x18, 0x0a, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x25,
0x04, 0x10, 0x04, 0x18, 0x0a, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x25, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, 0x04, 0x18, 0x0a, 0x52, 0x08, 0x70, 0x61, 0x73,
0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, 0x04, 0x18, 0x0a, 0x52, 0x08, 0x70, 0x61, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x6e,
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x69, 0x72, 0x73, 0x74,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x66, 0x69, 0x72, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73,
0x74, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xbe, 0x02, 0x0a, 0x04,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x32, 0xc7, 0x02, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x12, 0x62, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x2e, 0x63,
0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x62, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x2e,
0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e,
0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f,
0x75, 0x73, 0x65, 0x72, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x67, 0x0a, 0x05, 0x6c, 0x6f, 0x67,
0x69, 0x6e, 0x12, 0x1e, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x22, 0x12, 0x2f, 0x61, 0x70,
0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x3a,
0x01, 0x2a, 0x12, 0x72, 0x0a, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1e, 0x2e, 0x63,
0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e,
0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x63, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x63,
0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e,
0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x27, 0xba, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82,
0x45, 0x06, 0x08, 0x01, 0x12, 0x02, 0x31, 0x31, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x2a, 0x13, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75,
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x64, 0x65, 0x6c, 0x73, 0x65, 0x72, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x67, 0x0a, 0x05, 0x6c, 0x6f, 0x67, 0x69,
0x65, 0x74, 0x65, 0x3a, 0x01, 0x2a, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, 0x75, 0x73, 0x65, 0x6e, 0x12, 0x1e, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e,
0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x1f, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e,
0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, 0x22, 0x12, 0x2f, 0x61, 0x70, 0x69,
0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x3a, 0x01,
0x2a, 0x12, 0x69, 0x0a, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1e, 0x2e, 0x63, 0x6f,
0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c,
0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x63, 0x6f,
0x6d, 0x2e, 0x77, 0x65, 0x62, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x6c,
0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0x82, 0xd3,
0xe4, 0x93, 0x02, 0x18, 0x2a, 0x13, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73,
0x65, 0x72, 0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x3a, 0x01, 0x2a, 0x42, 0x09, 0x5a, 0x07,
0x2e, 0x2f, 0x3b, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

@ -9,6 +9,9 @@ import (
func main() { func main() {
app := gin.Default() app := gin.Default()
srv := service.UserService{} srv := service.UserService{}
app.Use(func(c *gin.Context) {
c.Set("userId", 11)
})
user.NewGin(app, &srv) user.NewGin(app, &srv)
app.Run("localhost:8888") app.Run("localhost:8888")
} }

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
user "git.echinacities.com/mogfee/protoc-gen-kit/proto/v1" user "git.echinacities.com/mogfee/protoc-gen-kit/proto/v1"
"git.echinacities.com/mogfee/protoc-gen-kit/xerrors" "git.echinacities.com/mogfee/protoc-gen-kit/xerrors"
) )
@ -20,6 +21,7 @@ func (*UserService) Login(ctx context.Context, req *user.LoginRequest) (*user.Lo
return &user.LoginResponse{Token: string(b)}, nil return &user.LoginResponse{Token: string(b)}, nil
} }
func (*UserService) List(ctx context.Context, req *user.LoginRequest) (*user.LoginResponse, error) { func (*UserService) List(ctx context.Context, req *user.LoginRequest) (*user.LoginResponse, error) {
fmt.Println(ctx.Value("userId"))
return nil, xerrors.InternalServer("InternalServer", "B") return nil, xerrors.InternalServer("InternalServer", "B")
b, _ := json.Marshal(req) b, _ := json.Marshal(req)

Loading…
Cancel
Save