1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
template.go 909 Bytes
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-04-22 18:06 . feat: add standard response
package resp
import "net/http"
func defaultResp() Response {
return r{}.
Status(http.StatusOK).
Message(http.StatusText(http.StatusOK)).
ContentType(ContentJSONHeaderValue)
}
func New(data interface{}) Response {
return defaultResp().Data(data)
}
func Ok() Response {
return defaultResp()
}
func Created(data interface{}) Response {
return defaultResp().Status(http.StatusCreated).Data(data)
}
func Error(httpStatus int, err error) Response {
return defaultResp().Status(httpStatus).Message(err.Error())
}
func InternalError(err error) Response {
return defaultResp().Status(http.StatusInternalServerError).Message(err.Error())
}
func BadRequest(msg string) Response {
return defaultResp().Status(http.StatusBadRequest).Data(msg)
}
func Redirect(location string) Response {
return defaultResp().Status(http.StatusFound).Message("Location").Data(location).ContentType(ContentRedirect)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.2.6

搜索帮助