123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- package v1_0
- import (
- "adm-gateway/errors"
- param_v1 "adm-gateway/param/v1"
- "adm-gateway/pb"
- v1 "adm-gateway/pb/v1"
- "fmt"
- "net/http"
- "github.com/gin-gonic/gin"
- "git.getensh.com/common/gopkgsv2/logger"
- "git.getensh.com/common/gopkgsv2/tasker/httptasker"
- "git.getensh.com/common/gopkgsv2/util"
- "go.uber.org/zap"
- )
- // API管理表 t_adm_api_management
- // APIList godoc
- // @Summary API管理
- // @Description API管理
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param api_no query string false "API编号"
- // @Param desc query string false "描述"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetAPIListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api [get]
- func (c *Controller) APIList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetAPIListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetAPIListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetAPIListResponse{}
- r := v1.APIListRequest{
- ApiNo: req.ApiNo,
- Desc: req.Desc,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.APIList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.APIList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.APIList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // CheckAPI godoc
- // @Summary 查看API
- // @Description 查看API
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param api_id query int64 true "API id"
- // @Success 200 {object} param_v1.GetCheckAPIResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/check [get]
- func (c *Controller) CheckAPI(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetCheckAPIRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetCheckAPIQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetCheckAPIResponse{}
- r := v1.CheckAPIRequest{
- ApiId: req.ApiId,
- }
- reply, err := pb.Management.CheckAPI(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.CheckAPI"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // DeleteAPI godoc
- // @Summary 删除API
- // @Description 删除API
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param api_id path int64 true "API id"
- // @Success 200 {object} param_v1.GetDeleteAPIResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/delete/{api_id} [delete]
- func (c *Controller) DeleteAPI(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetDeleteAPIRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, &req.GetDeleteAPIPath, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetDeleteAPIResponse{}
- r := v1.DeleteAPIRequest{
- ApiId: req.ApiId,
- }
- _, err := pb.Management.DeleteAPI(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DeleteAPI"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // 密钥管理表 t_adm_key_management
- // KeyList godoc
- // @Summary 密钥管理
- // @Description 密钥管理
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param key query string false "密钥"
- // @Param desc query string false "描述"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetKeyListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/key [get]
- func (c *Controller) KeyList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetKeyListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetKeyListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetKeyListResponse{}
- r := v1.KeyListRequest{
- Key: req.Key,
- Desc: req.Desc,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- reply, err := pb.Management.KeyList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.KeyList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply.List == nil {
- reply.List = make([]*v1.KeyList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // CreateKey godoc
- // @Summary 新增密钥
- // @Description 新增密钥
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.CreateKeyBody true "body"
- // @Success 200 {object} param_v1.CreateKeyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/key/create [post]
- func (c *Controller) CreateKey(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CreateKeyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.CreateKeyBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.CreateKeyResponse{}
- r := v1.CreateKeyRequest{
- Desc: req.Desc,
- }
- _, err := pb.Management.CreateKey(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.CreateKey"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // DeleteKey godoc
- // @Summary 删除key
- // @Description 删除key
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param key path string true "密钥"
- // @Success 200 {object} param_v1.DeleteKeyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/delete/key/{key} [delete]
- func (c *Controller) DeleteKey(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.DeleteKeyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, &req.DeleteKeyPath, nil, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.DeleteKeyResponse{}
- r := v1.DeleteKeyRequest{
- Key: req.Key,
- }
- _, err := pb.Management.DeleteKey(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.DeleteKey"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // AllAPI godoc
- // @Summary API列表
- // @Description API列表
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param all_api query string false "API"
- // @Success 200 {object} param_v1.AllAPIResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/search/all_api [get]
- func (c *Controller) AllAPI(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.AllAPIRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.AllAPIQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.AllAPIResponse{}
- r := v1.AllAPIRequest{
- AllApi: req.AllAPI,
- }
- reply, err := pb.Management.AllAPI(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.AllAPI"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // AllKey godoc
- // @Summary 密钥列表
- // @Description 密钥列表
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param all_key query string false "密钥"
- // @Success 200 {object} param_v1.AllKeyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/search/all_key [get]
- func (c *Controller) AllKey(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.AllKeyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.AllKeyQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.AllKeyResponse{}
- r := v1.AllKeyRequest{
- AllKey: req.AllKey,
- }
- reply, err := pb.Management.AllKey(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.AllKey"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply.List
- if resp.Data == nil {
- resp.Data = make([]string, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // UseAPI godoc
- // @Summary API查询
- // @Description API查询
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param api_id query int64 false "API id"
- // @Success 200 {object} param_v1.UseAPIResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/use_key [get]
- func (c *Controller) UseAPI(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UseAPIRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.UseAPIQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.UseAPIResponse{}
- r := v1.UseAPIRequest{
- ApiId: req.ApiId,
- }
- reply, err := pb.Management.UseAPI(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.UseAPI"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // UpdateAPI godoc
- // @Summary 更新API信息
- // @Description 更新API信息
- // @Tags api_management,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.UpdateAPIBody true "body"
- // @Success 200 {object} param_v1.UpdateAPIResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/api/update_api [put]
- func (c *Controller) UpdateAPI(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UpdateAPIRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateAPIBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- fmt.Println("1111111111")
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.UpdateAPIResponse{}
- r := v1.UpdateAPIRequest{
- Api: req.Api,
- Params: req.Param,
- Data: req.Data,
- }
- fmt.Println("2222222222")
- _, err := pb.Management.UpdateAPI(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.management.UpdateAPI"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|