123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "access-control-monitor/errors"
- "access-control-monitor/param/base"
- param_v1 "access-control-monitor/param/v1"
- "access-control-monitor/timetask"
- "access-control-monitor/utils"
- "fmt"
- "net/http"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- // 心跳
- // @Summary 心跳
- // @Description 心跳
- // @Tags heatbeat
- // @Accept json
- // @Produce json
- // @Param body body v1.PingBody true "sn"
- // @Success 200 {object} v1.PingResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /ping [put]
- func (c *Controller) Ping(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PingRequest{}
- resp := param_v1.PingResponse{Result: base.Result{
- Code: 0,
- Message: "成功",
- }}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.PingBody)
- bytes, _ := json.Marshal(req)
- fmt.Printf("ping read:%s\n", bytes)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- // 第一步本地缓存获取,本地缓存有直接返回,本地缓存无调用接口获取
- _, err := utils.GetDeviceInfo(req.Sn)
- if err != nil {
- return err
- }
- timetask.UpdateDustTime(req.Sn)
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|