mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-05 16:56:22 +00:00
⚡ implement user authentication and database initialization, add models for user, comment, label, and OIDC configuration
This commit is contained in:
38
pkg/resps/resps.go
Normal file
38
pkg/resps/resps.go
Normal file
@ -0,0 +1,38 @@
|
||||
package resps
|
||||
|
||||
import (
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/common/utils"
|
||||
)
|
||||
|
||||
func Custom(c *app.RequestContext, status int, message string, data any) {
|
||||
c.JSON(status, utils.H{
|
||||
"status": status,
|
||||
"message": message,
|
||||
"data": data,
|
||||
})
|
||||
}
|
||||
|
||||
func Ok(c *app.RequestContext, message string, data any) {
|
||||
Custom(c, 200, message, data)
|
||||
}
|
||||
|
||||
func BadRequest(c *app.RequestContext, message string) {
|
||||
Custom(c, 400, message, nil)
|
||||
}
|
||||
|
||||
func UnAuthorized(c *app.RequestContext, message string) {
|
||||
Custom(c, 401, message, nil)
|
||||
}
|
||||
|
||||
func Forbidden(c *app.RequestContext, message string) {
|
||||
Custom(c, 403, message, nil)
|
||||
}
|
||||
|
||||
func NotFound(c *app.RequestContext, message string) {
|
||||
Custom(c, 404, message, nil)
|
||||
}
|
||||
|
||||
func InternalServerError(c *app.RequestContext, message string) {
|
||||
Custom(c, 500, message, nil)
|
||||
}
|
8
pkg/resps/texts.go
Normal file
8
pkg/resps/texts.go
Normal file
@ -0,0 +1,8 @@
|
||||
package resps
|
||||
|
||||
const (
|
||||
ErrParamInvalid = "invalid request parameters"
|
||||
ErrUnauthorized = "unauthorized access"
|
||||
ErrForbidden = "access forbidden"
|
||||
ErrNotFound = "resource not found"
|
||||
)
|
Reference in New Issue
Block a user