mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
50 lines
1.1 KiB
Go
Executable File
50 lines
1.1 KiB
Go
Executable File
package helper
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"net/http"
|
|
|
|
"github.com/xinliangnote/go-gin-api/internal/code"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
)
|
|
|
|
type md5Request struct {
|
|
Str string `uri:"str" binding:"required"` // 需要加密的字符串
|
|
}
|
|
|
|
type md5Response struct {
|
|
Md5Str string `json:"md5_str"` // MD5后的字符串
|
|
}
|
|
|
|
// Md5 加密
|
|
// @Summary 加密
|
|
// @Description 加密
|
|
// @Tags Helper
|
|
// @Accept application/x-www-form-urlencoded
|
|
// @Produce json
|
|
// @Param str path string true "需要加密的字符串"
|
|
// @Success 200 {object} md5Response
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /helper/md5/{str} [get]
|
|
func (h *handler) Md5() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(md5Request)
|
|
res := new(md5Response)
|
|
|
|
if err := ctx.ShouldBindURI(req); err != nil {
|
|
ctx.AbortWithError(core.Error(
|
|
http.StatusBadRequest,
|
|
code.ParamBindError,
|
|
code.Text(code.ParamBindError)).WithError(err),
|
|
)
|
|
return
|
|
}
|
|
|
|
m := md5.New()
|
|
m.Write([]byte(req.Str))
|
|
res.Md5Str = hex.EncodeToString(m.Sum(nil))
|
|
ctx.Payload(res)
|
|
}
|
|
}
|