remove some runtime allocaions
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
bce3839877
commit
c7ec840ac0
26
util.go
26
util.go
@ -10,6 +10,20 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
httpMethodMap = map[string]string{
|
||||||
|
"GET": "MethodGet",
|
||||||
|
"HEAD": "MethodHead",
|
||||||
|
"POST": "MethodPost",
|
||||||
|
"PUT": "MethodPut",
|
||||||
|
"PATCH": "MethodPatch",
|
||||||
|
"DELETE": "MethodDelete",
|
||||||
|
"CONNECT": "MethodConnect",
|
||||||
|
"OPTIONS": "MethodOptions",
|
||||||
|
"TRACE": "MethodTrace",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func unexport(s string) string {
|
func unexport(s string) string {
|
||||||
return strings.ToLower(s[:1]) + s[1:]
|
return strings.ToLower(s[:1]) + s[1:]
|
||||||
}
|
}
|
||||||
@ -61,9 +75,15 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
|
|||||||
gfile.P("opts = append(opts,")
|
gfile.P("opts = append(opts,")
|
||||||
endpoints, _ := generateEndpoints(method)
|
endpoints, _ := generateEndpoints(method)
|
||||||
path, method, body := getEndpoint(endpoints[0])
|
path, method, body := getEndpoint(endpoints[0])
|
||||||
|
if vmethod, ok := httpMethodMap[method]; ok {
|
||||||
|
gfile.P(microClientHttpPackage.Ident("Method"), `(`, httpPackage.Ident(vmethod), `),`)
|
||||||
|
} else {
|
||||||
gfile.P(microClientHttpPackage.Ident("Method"), `("`, method, `"),`)
|
gfile.P(microClientHttpPackage.Ident("Method"), `("`, method, `"),`)
|
||||||
|
}
|
||||||
gfile.P(microClientHttpPackage.Ident("Path"), `("`, path, `"),`)
|
gfile.P(microClientHttpPackage.Ident("Path"), `("`, path, `"),`)
|
||||||
|
if body != "" {
|
||||||
gfile.P(microClientHttpPackage.Ident("Body"), `("`, body, `"),`)
|
gfile.P(microClientHttpPackage.Ident("Body"), `("`, body, `"),`)
|
||||||
|
}
|
||||||
gfile.P(")")
|
gfile.P(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -539,8 +559,12 @@ func generateEndpoint(gfile *protogen.GeneratedFile, serviceName string, methodN
|
|||||||
path, meth, body := getEndpoint(rule)
|
path, meth, body := getEndpoint(rule)
|
||||||
gfile.P("Name:", fmt.Sprintf(`"%s.%s",`, serviceName, methodName))
|
gfile.P("Name:", fmt.Sprintf(`"%s.%s",`, serviceName, methodName))
|
||||||
gfile.P("Path:", fmt.Sprintf(`[]string{"%s"},`, path))
|
gfile.P("Path:", fmt.Sprintf(`[]string{"%s"},`, path))
|
||||||
|
if vmethod, ok := httpMethodMap[meth]; ok {
|
||||||
|
gfile.P("Method:", `[]string{`, httpPackage.Ident(vmethod), `},`)
|
||||||
|
} else {
|
||||||
gfile.P("Method:", fmt.Sprintf(`[]string{"%s"},`, meth))
|
gfile.P("Method:", fmt.Sprintf(`[]string{"%s"},`, meth))
|
||||||
if len(rule.GetGet()) == 0 {
|
}
|
||||||
|
if len(rule.GetGet()) == 0 && body != "" {
|
||||||
gfile.P("Body:", fmt.Sprintf(`"%s",`, body))
|
gfile.P("Body:", fmt.Sprintf(`"%s",`, body))
|
||||||
}
|
}
|
||||||
if streaming {
|
if streaming {
|
||||||
|
Loading…
Reference in New Issue
Block a user