Skip to content

Commit

Permalink
change tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Jan 26, 2024
1 parent 0d25abe commit bab23b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cmd/hz/generator/package_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,10 @@ func (r *request) setHeader(header, value string) *request {
return r
}
func (r *request) addHeader(header, value string) *request {
r.header.Add(header, value)
func (r *request) addHeaders(headers map[string]string) *request {
for k, v := range headers {
r.setHeader(k, v)
}
return r
}
Expand Down Expand Up @@ -923,7 +925,7 @@ func New{{.ServiceName}}Client(hostUrl string, ops ...Option) (Client, error) {
{{range $_, $MethodInfo := .ClientMethods}}
func (s *{{$.ServiceName}}Client) {{$MethodInfo.Name}}(context context.Context, req *{{$MethodInfo.RequestTypeName}}, reqOpt ...config.RequestOption) (resp *{{$MethodInfo.ReturnTypeName}}, rawResponse *protocol.Response, err error) {
httpResp := &{{$MethodInfo.ReturnTypeName}}{}
httpResp := &{{$MethodInfo.ReturnTypeName}}{}
ret, err := s.client.r().
setContext(context).
setQueryParams(map[string]interface{}{
Expand All @@ -944,7 +946,7 @@ func (s *{{$.ServiceName}}Client) {{$MethodInfo.Name}}(context context.Context,
{{$MethodInfo.BodyParamsCode}}
setRequestOption(reqOpt...).
setResult(httpResp).
execute("{{$MethodInfo.HTTPMethod}}", "{{$MethodInfo.Path}}")
execute("{{ ConvertClientHttpMethod $MethodInfo.HTTPMethod }}", "{{$MethodInfo.Path}}")
if err != nil {
return nil, nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/hz/generator/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (

var funcMap = func() template.FuncMap {
m := template.FuncMap{
"GetUniqueHandlerOutDir": getUniqueHandlerOutDir,
"ToSnakeCase": util.ToSnakeCase,
"Split": strings.Split,
"Trim": strings.Trim,
"GetUniqueHandlerOutDir": getUniqueHandlerOutDir,
"ToSnakeCase": util.ToSnakeCase,
"Split": strings.Split,
"Trim": strings.Trim,
"ConvertClientHttpMethod": util.ConvertClientHttpMethod,
}
for key, f := range sprig.TxtFuncMap() {
m[key] = f
Expand Down
8 changes: 8 additions & 0 deletions cmd/hz/util/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ func SnakeString(s string) string {
}
return strings.ToLower(Bytes2Str(data))
}

// ConvertClientHttpMethod converts the ANY to POST for generating client http method
func ConvertClientHttpMethod(m string) string {
if strings.ToUpper(m) == "ANY" {
return "POST"
}
return m
}

0 comments on commit bab23b3

Please sign in to comment.