gozero-utils.git

module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2022 License: Apache-2.0

README

gozero utils

自定义统一返回响应格式

相关文件
  • errorx/baseError.go
  • response/response.go
修改goctl模板

官网文档 https://go-zero.dev/cn/docs/advance/template
如果本地没有~/.goctl/${goctl版本号}/api/handler.tpl文件,可以通过模板初始化命令goctl template init进行初始化

handler.tpl

package {{.PkgName}}

import (
  "net/http"
  "gitee.com/NinjaFf/gozero-utils.git/response"
  {{.ImportPackages}}
)

func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
  return func(w http.ResponseWriter, r *http.Request) {
    {{if .HasRequest}}var req types.{{.RequestType}}
    if err := httpx.Parse(r, &req); err != nil {
      httpx.Error(w, err)
      return
    }

    {{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
    {{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}})

    {{if .HasResp}}response.Response(w, resp, err){{else}}response.Response(w, nil, err){{end}}
  }
}

JWT

相关文件
  • jwtx/jwt.go
demo
accessToken, err := jwtx.GetToken(l.svcCtx.Config.Auth.AccessSecret, time.Now().Unix(), l.svcCtx.Config.Auth.AccessExpire, res.Account)

regen api

goctl api go -api xxx.api -dir .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL