some fixes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
59ee7bc1de
commit
506f19310f
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,5 +34,5 @@ _cgo_export.*
|
|||||||
*~
|
*~
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
/protoc-gen-micro
|
/protoc-gen-go-micro
|
||||||
|
|
||||||
|
42
util.go
42
util.go
@ -2,24 +2,27 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
api_options "go.unistack.org/micro-proto/v3/api"
|
api_options "go.unistack.org/micro-proto/v3/api"
|
||||||
openapiv2_options "go.unistack.org/micro-proto/v3/openapiv2"
|
v2 "go.unistack.org/micro-proto/v3/openapiv2"
|
||||||
|
v3 "go.unistack.org/micro-proto/v3/openapiv3"
|
||||||
"google.golang.org/protobuf/compiler/protogen"
|
"google.golang.org/protobuf/compiler/protogen"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpMethodMap = map[string]string{
|
var httpMethodMap = map[string]string{
|
||||||
"GET": "MethodGet",
|
http.MethodGet: "MethodGet",
|
||||||
"HEAD": "MethodHead",
|
http.MethodHead: "MethodHead",
|
||||||
"POST": "MethodPost",
|
http.MethodPost: "MethodPost",
|
||||||
"PUT": "MethodPut",
|
http.MethodPut: "MethodPut",
|
||||||
"PATCH": "MethodPatch",
|
http.MethodPatch: "MethodPatch",
|
||||||
"DELETE": "MethodDelete",
|
http.MethodDelete: "MethodDelete",
|
||||||
"CONNECT": "MethodConnect",
|
http.MethodConnect: "MethodConnect",
|
||||||
"OPTIONS": "MethodOptions",
|
http.MethodOptions: "MethodOptions",
|
||||||
"TRACE": "MethodTrace",
|
http.MethodTrace: "MethodTrace",
|
||||||
}
|
}
|
||||||
|
|
||||||
func unexport(s string) string {
|
func unexport(s string) string {
|
||||||
@ -49,10 +52,10 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
generateClientFuncSignature(gfile, serviceName, method)
|
generateClientFuncSignature(gfile, serviceName, method)
|
||||||
|
|
||||||
if http && method.Desc.Options() != nil {
|
if http && method.Desc.Options() != nil {
|
||||||
if proto.HasExtension(method.Desc.Options(), openapiv2_options.E_Openapiv2Operation) {
|
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
|
||||||
opts := proto.GetExtension(method.Desc.Options(), openapiv2_options.E_Openapiv2Operation)
|
opts := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
|
||||||
if opts != nil {
|
if opts != nil {
|
||||||
r := opts.(*openapiv2_options.Operation)
|
r := opts.(*v2.Operation)
|
||||||
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseCode), ")")
|
gfile.P("errmap := make(map[string]interface{}, ", len(r.Responses.ResponseCode), ")")
|
||||||
for _, rsp := range r.Responses.ResponseCode {
|
for _, rsp := range r.Responses.ResponseCode {
|
||||||
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
if schema := rsp.Value.GetJsonReference(); schema != nil {
|
||||||
@ -60,7 +63,7 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
|
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
|
||||||
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
|
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
|
||||||
}
|
}
|
||||||
if ref == "micro.codec.Frame" {
|
if ref == "micro.codec.Frame" || ref == ".micro.codec.Frame" {
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
|
||||||
} else {
|
} else {
|
||||||
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
|
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
|
||||||
@ -68,11 +71,11 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gfile.P("opts = append(opts,")
|
gfile.P("opts = append(opts,")
|
||||||
gfile.P(microClientHttpPackage.Ident("ErrorMap"), "(errmap),")
|
gfile.P(microClientHttpPackage.Ident("ErrorMap"), "(errmap),")
|
||||||
gfile.P(")")
|
gfile.P(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||||
gfile.P("opts = append(opts,")
|
gfile.P("opts = append(opts,")
|
||||||
endpoints, _ := generateEndpoints(method)
|
endpoints, _ := generateEndpoints(method)
|
||||||
@ -88,7 +91,16 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
}
|
}
|
||||||
gfile.P(")")
|
gfile.P(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build a list of header parameters.
|
||||||
|
eopt := proto.GetExtension(method.Desc.Options(), v3.E_Openapiv3Operation)
|
||||||
|
if eopt != nil && eopt != v3.E_Openapiv3Operation.InterfaceOf(v3.E_Openapiv3Operation.Zero()) {
|
||||||
|
opt := eopt.(*v3.Operation)
|
||||||
|
log.Printf("xxx %#+v\n", opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if rule, ok := getMicroApiMethod(method); ok {
|
if rule, ok := getMicroApiMethod(method); ok {
|
||||||
if rule.Timeout > 0 {
|
if rule.Timeout > 0 {
|
||||||
gfile.P("opts = append(opts, ", microClientPackage.Ident("WithRequestTimeout"), "(", timePackage.Ident("Second"), "*", rule.Timeout, "))")
|
gfile.P("opts = append(opts, ", microClientPackage.Ident("WithRequestTimeout"), "(", timePackage.Ident("Second"), "*", rule.Timeout, "))")
|
||||||
|
Loading…
Reference in New Issue
Block a user