Skip to content

Commit

Permalink
fix(hz): fix some problems with hz client code (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Jan 30, 2024
1 parent 0d25abe commit 0619701
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/hz/generator/package_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ func (r *request) addHeader(header, value string) *request {
return r
}
func (r *request) addHeaders(params map[string]string) *request {
for k, v := range params {
r.addHeader(k, v)
}
return r
}
func (r *request) setQueryParam(param string, value interface{}) *request {
v := reflect.ValueOf(value)
switch v.Kind() {
Expand Down Expand Up @@ -923,7 +931,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 +952,7 @@ func (s *{{$.ServiceName}}Client) {{$MethodInfo.Name}}(context context.Context,
{{$MethodInfo.BodyParamsCode}}
setRequestOption(reqOpt...).
setResult(httpResp).
execute("{{$MethodInfo.HTTPMethod}}", "{{$MethodInfo.Path}}")
execute("{{if EqualFold $MethodInfo.HTTPMethod "Any"}}POST{{else}}{{ $MethodInfo.HTTPMethod }}{{end}}", "{{$MethodInfo.Path}}")
if err != nil {
return nil, nil, err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/hz/generator/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var funcMap = func() template.FuncMap {
"ToSnakeCase": util.ToSnakeCase,
"Split": strings.Split,
"Trim": strings.Trim,
"EqualFold": strings.EqualFold,
}
for key, f := range sprig.TxtFuncMap() {
m[key] = f
Expand Down

0 comments on commit 0619701

Please sign in to comment.