/** * @Author: jager * @Email: lhj168os@gmail.com * @File: almanac * @Date: 2022/1/6 6:13 下午 * @package: almanac * @Version: v1.0.0 * * @Description: * */ package almanac import ( "github.com/gin-gonic/gin" "github.com/jageros/hawox/astro" "github.com/jageros/hawox/errcode" "github.com/jageros/hawox/httpx" "idata/internal/apity" "idata/internal/consts" "idata/internal/service/user" "strconv" "strings" "time" ) func Almanac(ctx *gin.Context) { if !user.Auth(ctx, apity.Almanac) { return } date, ok := httpx.DecodeUrlVal(ctx, "date") if !ok || date == "" { date = time.Now().Format(consts.DateFormat) } strs := strings.Split(date, "_") var hour = -1 if len(strs) >= 2 { h, err := strconv.Atoi(strs[1]) if err == nil { hour = h } } dd := astro.GetDate(strs[0]) if dd == nil { httpx.ErrInterrupt(ctx, errcode.InvalidParam) return } data, err := dd.Map(hour) if err != nil { httpx.ErrInterrupt(ctx, errcode.WithErrcode(2, err)) return } httpx.PkgMsgWrite(ctx, data) }