authorization enforced on webpages
This commit is contained in:
@@ -48,6 +48,12 @@ func Forbidden() ErrorResponse {
|
||||
}
|
||||
}
|
||||
|
||||
func Conflict() ErrorResponse {
|
||||
return ErrorResponse{
|
||||
status: http.StatusConflict,
|
||||
}
|
||||
}
|
||||
|
||||
// builder pattern implementation
|
||||
|
||||
func (e ErrorResponse) Msg(msg string) ErrorResponse {
|
||||
@@ -55,6 +61,11 @@ func (e ErrorResponse) Msg(msg string) ErrorResponse {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e ErrorResponse) Msgf(format string, args ...any) ErrorResponse {
|
||||
e.msg = fmt.Sprintf(format, args...)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e ErrorResponse) Status(status int) ErrorResponse {
|
||||
e.status = status
|
||||
return e
|
||||
@@ -92,33 +103,33 @@ func (e ErrorResponse) Unwrap() error {
|
||||
|
||||
// nested response value resolution
|
||||
|
||||
func (e ErrorResponse) getStatus() (int, bool) {
|
||||
func (e ErrorResponse) GetStatus() (int, bool) {
|
||||
if e.status != 0 {
|
||||
return e.status, true
|
||||
}
|
||||
|
||||
ce, ok := getError(e.err)
|
||||
ce, ok := GetError(e.err)
|
||||
if ok {
|
||||
return ce.getStatus()
|
||||
return ce.GetStatus()
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (e ErrorResponse) getMsg() (string, bool) {
|
||||
func (e ErrorResponse) GetMsg() (string, bool) {
|
||||
if e.msg != "" {
|
||||
return e.msg, true
|
||||
}
|
||||
|
||||
ce, ok := getError(e.err)
|
||||
ce, ok := GetError(e.err)
|
||||
if ok {
|
||||
return ce.getMsg()
|
||||
return ce.GetMsg()
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
func getError(err error) (e ErrorResponse, ok bool) {
|
||||
func GetError(err error) (e ErrorResponse, ok bool) {
|
||||
ok = errors.As(err, &e)
|
||||
return e, ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user