♻️ Use standard getter/setter names
This commit is contained in:
parent
7fd3192f51
commit
f27c669aeb
5 changed files with 41 additions and 37 deletions
12
errorf.go
12
errorf.go
|
|
@ -14,7 +14,7 @@ import (
|
|||
//
|
||||
// If you want a different user message, use Msg, such as:
|
||||
//
|
||||
// err := errors.Errorf(http.StatusNotFound, "%w", sqlError).Msg("user not found %d", userId)
|
||||
// err := errors.Errorf(http.StatusNotFound, "%w", sqlError).SetMsg("user not found %d", userId)
|
||||
func Errorf(status int, format string, parts ...any) SettableError {
|
||||
if len(parts) == 0 {
|
||||
return &erf{status, format, ""}
|
||||
|
|
@ -41,7 +41,7 @@ type erf struct {
|
|||
msg string
|
||||
}
|
||||
|
||||
func (e *erf) GetStatus() int {
|
||||
func (e *erf) Status() int {
|
||||
if e.stat < http.StatusContinue || e.stat >= 600 {
|
||||
e.stat = http.StatusInternalServerError
|
||||
}
|
||||
|
|
@ -52,15 +52,15 @@ func (e *erf) Error() string {
|
|||
return e.err
|
||||
}
|
||||
|
||||
func (e *erf) GetMsg() string {
|
||||
func (e *erf) Msg() string {
|
||||
if e.msg == "" {
|
||||
return e.err
|
||||
}
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func (e *erf) Status(status int) SettableError {
|
||||
// GetStatus already handles invalid values, so we'll just ignore this.
|
||||
func (e *erf) SetStatus(status int) SettableError {
|
||||
// Status already handles invalid values, so we'll just ignore this.
|
||||
if status < http.StatusContinue || status >= 600 {
|
||||
return e
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ func (e *erf) Status(status int) SettableError {
|
|||
return e
|
||||
}
|
||||
|
||||
func (e *erf) Msg(msg string, parts ...any) SettableError {
|
||||
func (e *erf) SetMsg(msg string, parts ...any) SettableError {
|
||||
e.msg = msg
|
||||
if len(parts) > 0 {
|
||||
e.msg = fmt.Sprintf(msg, parts...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue