|
|
@ -15,6 +15,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
httpx.ErrorCtx(r.Context(), w, err) |
|
|
httpx.ErrorCtx(r.Context(), w, err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
{{end}} |
|
|
// 获取请求头里的token |
|
|
// 获取请求头里的token |
|
|
token := r.Header.Get("Authorization") |
|
|
token := r.Header.Get("Authorization") |
|
|
// 如果有token, 使用context传值到logic中 |
|
|
// 如果有token, 使用context传值到logic中 |
|
|
@ -22,7 +23,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|
|
ctx := context.WithValue(r.Context(), "token", token) |
|
|
ctx := context.WithValue(r.Context(), "token", token) |
|
|
r = r.WithContext(ctx) |
|
|
r = r.WithContext(ctx) |
|
|
} |
|
|
} |
|
|
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx) |
|
|
l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx) |
|
|
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}}) |
|
|
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
httpx.ErrorCtx(r.Context(), w, err) |
|
|
httpx.ErrorCtx(r.Context(), w, err) |
|
|
|