feat: 增加获取服务器时间接口
This commit is contained in:
@@ -22,6 +22,16 @@ func Setup(router *gin.Engine) {
|
|||||||
controller.NewIndex.Handler,
|
controller.NewIndex.Handler,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 路由服务器时间
|
||||||
|
router.GET("/time",
|
||||||
|
middleware.RateLimit(middleware.LimitOption{
|
||||||
|
Time: 60,
|
||||||
|
Count: 10,
|
||||||
|
Type: middleware.LIMIT_IP,
|
||||||
|
}),
|
||||||
|
controller.NewTimestamp.Handler,
|
||||||
|
)
|
||||||
|
|
||||||
// 通用请求
|
// 通用请求
|
||||||
commonGroup := router.Group("/common")
|
commonGroup := router.Group("/common")
|
||||||
{
|
{
|
||||||
|
|||||||
46
src/modules/common/controller/timestamp.go
Normal file
46
src/modules/common/controller/timestamp.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"be.ems/src/framework/resp"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化控制层 TimestampController 结构体
|
||||||
|
var NewTimestamp = &TimestampController{}
|
||||||
|
|
||||||
|
// 服务器时间
|
||||||
|
//
|
||||||
|
// PATH /time
|
||||||
|
type TimestampController struct{}
|
||||||
|
|
||||||
|
// Handler 路由
|
||||||
|
//
|
||||||
|
// GET /
|
||||||
|
//
|
||||||
|
// @Tags common
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} object "Response Results"
|
||||||
|
// @Summary Server Time
|
||||||
|
// @Description Server Time
|
||||||
|
// @Router / [get]
|
||||||
|
func (s TimestampController) Handler(c *gin.Context) {
|
||||||
|
now := time.Now()
|
||||||
|
// 获取当前时间戳
|
||||||
|
timestamp := now.UnixMilli()
|
||||||
|
// 获取时区
|
||||||
|
timezone := now.Format("-0700")
|
||||||
|
// 获取时区名称
|
||||||
|
timezoneName := now.Format("MST")
|
||||||
|
// 获取 RFC3339 格式的时间
|
||||||
|
rfc3339 := now.Format(time.RFC3339)
|
||||||
|
c.JSON(200, resp.OkData(map[string]any{
|
||||||
|
"timestamp": timestamp,
|
||||||
|
"timezone": timezone,
|
||||||
|
"timezoneName": timezoneName,
|
||||||
|
"rfc3339": rfc3339,
|
||||||
|
}))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user