1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-17 09:37:02 +00:00

implement setters and change to call it from constructor

This commit is contained in:
teru
2016-08-05 18:26:54 +09:00
parent c7d3c62281
commit 215df0c819
3 changed files with 89 additions and 30 deletions

34
user.go
View File

@@ -25,29 +25,49 @@ func (p UserSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// NewUser creates a new User instance.
func NewUser(name, hashedPassword string, forwards []string) (*User, error) {
if !validUserName(name) {
return nil, ErrInvalidUserName
u := &User{}
if err := u.setName(name); err != nil {
return nil, err
}
u := &User{
name: name,
hashedPassword: hashedPassword,
forwards: forwards,
}
u.SetHashedPassword(hashedPassword)
u.SetForwards(forwards)
return u, nil
}
// setName sets the name.
func (u *User) setName(name string) error {
if !validUserName(name) {
return ErrInvalidUserName
}
u.name = name
return nil
}
// Name returns name.
func (u *User) Name() string {
return u.name
}
// SetHashedPassword sets the hashed password.
func (u *User) SetHashedPassword(hashedPassword string) {
u.hashedPassword = hashedPassword
}
// HashedPassword returns hashedPassword.
func (u *User) HashedPassword() string {
return u.hashedPassword
}
// SetForwards sets forwards.
func (u *User) SetForwards(forwards []string) {
u.forwards = forwards
}
// Forwards returns forwards.
func (u *User) Forwards() []string {
return u.forwards