Alejandro Mery
1 year ago
2 changed files with 88 additions and 18 deletions
@ -0,0 +1,49 @@
|
||||
package htpasswd |
||||
|
||||
import ( |
||||
"errors" |
||||
"strings" |
||||
) |
||||
|
||||
var ( |
||||
// ErrExists indicates the specified user already exists
|
||||
ErrExists = errors.New("user already exists") |
||||
// ErrNotExists indicates the specified user does not exist
|
||||
ErrNotExists = errors.New("user does not exist") |
||||
// ErrInvalidAlgorithm indicates the htpasswd entry doesn't contain a
|
||||
// valid algorithm signature
|
||||
ErrInvalidAlgorithm = errors.New("invalid algorithm") |
||||
// ErrInvalidPassword indicates the offered password doesn't match
|
||||
ErrInvalidPassword = errors.New("invalid password") |
||||
) |
||||
|
||||
// UserError indicates an error associated to the specified user
|
||||
type UserError struct { |
||||
Name string |
||||
Hint string |
||||
Err error |
||||
} |
||||
|
||||
func (e *UserError) Error() string { |
||||
var buf strings.Builder |
||||
var reason string |
||||
|
||||
if e.Hint != "" { |
||||
reason = e.Hint |
||||
} else { |
||||
reason = e.Err.Error() |
||||
} |
||||
|
||||
if e.Name == "" { |
||||
return reason |
||||
} |
||||
|
||||
_, _ = buf.WriteString(e.Name) |
||||
_, _ = buf.WriteString(": ") |
||||
_, _ = buf.WriteString(reason) |
||||
return buf.String() |
||||
} |
||||
|
||||
func (e *UserError) Unwrap() error { |
||||
return e.Err |
||||
} |
Loading…
Reference in new issue