1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-28 13:48:49 +08:00
2018-05-17 20:17:02 +02:00

34 lines
783 B
Go

package users
import "github.com/asaskevich/govalidator"
// User represents a Mainflux user account. Each user is identified given its
// email and password.
type User struct {
Email string
Password string
}
// Validate returns an error if user representation is invalid.
func (u User) Validate() error {
if u.Email == "" || u.Password == "" {
return ErrMalformedEntity
}
if !govalidator.IsEmail(u.Email) {
return ErrMalformedEntity
}
return nil
}
// UserRepository specifies an account persistence API.
type UserRepository interface {
// Save persists the user account. A non-nil error is returned to indicate
// operation failure.
Save(User) error
// RetrieveByID retrieves user by its unique identifier (i.e. email).
RetrieveByID(string) (User, error)
}