♻️ Use standard getter/setter names

This commit is contained in:
Dan Jones 2024-01-19 22:37:13 -06:00
commit f27c669aeb
5 changed files with 41 additions and 37 deletions

View file

@ -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...)