Library/models/error.go

20 lines
498 B
Go
Raw Normal View History

2018-01-23 13:31:54 +00:00
package models
import "fmt"
// ErrUsernameExists represents a "UsernameAlreadyExists" kind of error.
type ErrUsernameExists struct {
2018-01-23 13:32:23 +00:00
UserID int64
2018-01-23 13:31:54 +00:00
Username string
}
// IsErrUsernameExists checks if an error is a ErrUsernameExists.
func IsErrUsernameExists(err error) bool {
_, ok := err.(ErrUsernameExists)
return ok
}
func (err ErrUsernameExists) Error() string {
return fmt.Sprintf("a user with this username does already exist [user id: %d, username: %s]", err.UserID, err.Username)
2018-01-23 13:32:23 +00:00
}