// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package v1_0 import ( "net/http" "adm-data-gateway/errors" param_v1 "adm-data-gateway/param/v1" "adm-data-gateway/pb" v1 "adm-data-gateway/pb/v1" // 这个加别名,区别其它目录的v1 "git.getensh.com/common/gopkgsv2/logger" "git.getensh.com/common/gopkgsv2/tasker/httptasker" "git.getensh.com/common/gopkgsv2/util" "go.uber.org/zap" "github.com/gin-gonic/gin" ) // query godoc // @Summary API查询 // @Description API查询 // @Tags query,v1.0 // @Accept json // @Produce json // @Param appkey header string true "appkey" // @Param ts header string true "timestamp" // @Param sign header string true "签名" // @Param body body param_v1.QueryBody true "body" // @Success 200 {object} v1.QueryResponse "响应信息" // @Failure 500 {object} base.HTTPError // @Router /api/v1.0/query [post] func (c *Controller) Query(ctx *gin.Context) { // 解析参数 req := ¶m_v1.QueryRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.QueryBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { // rpc调用 req := &v1.QueryRequest{ Code: req.Api, Params: req.Param, } res, err := pb.Data.Query(ctx.Request.Context(), req) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Data.Query"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } // 响应数据 resp := ¶m_v1.QyeryResponse{ Data: res.Data, } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }