package protogen import ( "git.diulo.com/mogfee/kit/third_party/auth" "github.com/golang/protobuf/proto" "google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/types/descriptorpb" ) const ( METHOD_GET = "GET" METHOD_POST = "POST" METHOD_DELETE = "DELETE" ) func GetProtoMethod(m *protogen.Method) (method string, path string) { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if opts, err := proto.GetExtension(op, annotations.E_Http); err != nil { //log.Println(err) } else { if vv, ok := opts.(*annotations.HttpRule); ok { if vvv, ok := vv.Pattern.(*annotations.HttpRule_Get); ok { return METHOD_GET, vvv.Get } else if vvv, ok := vv.Pattern.(*annotations.HttpRule_Post); ok { return METHOD_POST, vvv.Post } else if vvv, ok := vv.Pattern.(*annotations.HttpRule_Delete); ok { return METHOD_DELETE, vvv.Delete } } } } return "", "" } func GetAuthKey(m *protogen.Method) string { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if opts, err := proto.GetExtension(op, auth.E_AuthKey); err != nil { //log.Println(err) } else { if vv, ok := opts.(*string); ok { return *vv } } } return "" }