init project
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package errors
|
||||
|
||||
import "net/http"
|
||||
|
||||
const (
|
||||
Success Code = "20000"
|
||||
ServerError Code = "50000"
|
||||
BadRequest Code = "40000"
|
||||
InvalidRequest Code = "40001"
|
||||
Unauthorized Code = "40100"
|
||||
Forbidden Code = "40300"
|
||||
Timeout Code = "50400"
|
||||
)
|
||||
|
||||
type Code string
|
||||
|
||||
var (
|
||||
codeMap = map[Code]string{
|
||||
Success: "Success",
|
||||
BadRequest: "Bad or invalid request",
|
||||
Unauthorized: "Unauthorized Token",
|
||||
Timeout: "Gateway Timeout",
|
||||
ServerError: "Internal Server Error",
|
||||
Forbidden: "Forbidden",
|
||||
InvalidRequest: "Invalid Request",
|
||||
}
|
||||
|
||||
codeHTTPMap = map[Code]int{
|
||||
Success: http.StatusOK,
|
||||
BadRequest: http.StatusBadRequest,
|
||||
Unauthorized: http.StatusUnauthorized,
|
||||
Timeout: http.StatusGatewayTimeout,
|
||||
ServerError: http.StatusInternalServerError,
|
||||
Forbidden: http.StatusForbidden,
|
||||
InvalidRequest: http.StatusUnprocessableEntity,
|
||||
}
|
||||
)
|
||||
|
||||
func (c Code) GetMessage() string {
|
||||
return codeMap[c]
|
||||
}
|
||||
|
||||
func (c Code) GetHTTPCode() int {
|
||||
return codeHTTPMap[c]
|
||||
}
|
||||
|
||||
func (c Code) GetCode() string {
|
||||
return string(c)
|
||||
}
|
||||
Reference in New Issue
Block a user