From af1e58bce9f8f23cd4c8a2e2d9c2ed7e6f707e27 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 19 Sep 2024 01:43:05 -0700 Subject: [PATCH] update: add resp 418 --- nft/resp/resp.go | 15 ++++++++++++++- nft/resp/var.go | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/nft/resp/resp.go b/nft/resp/resp.go index 1ef328d..76ec519 100644 --- a/nft/resp/resp.go +++ b/nft/resp/resp.go @@ -2,9 +2,10 @@ package resp import ( "fmt" - "github.com/loveuer/nf" "strconv" "strings" + + "github.com/loveuer/nf" ) func handleEmptyMsg(status uint32, msg string) string { @@ -102,6 +103,18 @@ func Resp403(c *nf.Ctx, data any, msgs ...string) error { return Resp(c, 403, msg, err, data) } +func Resp418(c *nf.Ctx, data any, msgs ...string) error { + msg := MSG418 + err := "" + + if len(msgs) > 0 && msgs[0] != "" { + msg = fmt.Sprintf("%s: %s", msg, strings.Join(msgs, "; ")) + err = "" + } + + return Resp(c, 418, msg, err, data) +} + func Resp429(c *nf.Ctx, data any, msgs ...string) error { msg := MSG429 err := "" diff --git a/nft/resp/var.go b/nft/resp/var.go index 067939e..af32154 100644 --- a/nft/resp/var.go +++ b/nft/resp/var.go @@ -7,6 +7,7 @@ const ( MSG401 = "登录已过期, 请重新登录" MSG403 = "请求权限不足" MSG404 = "请求资源未找到" + MSG418 = "请求条件不满足, 请稍后再试" MSG429 = "请求过于频繁, 请稍后再试" MSG500 = "服务器开小差了, 请稍后再试" MSG501 = "功能开发中, 尽情期待"