package auth type User interface { GetUsername() string GetName() string GetSurname() string GetFullName() string } type Session interface { GetUsername() string GetToken() string } type AuthenticatorService interface { GetUser(username string) (User, error) GetUsers() ([]User, error) GetSession(token string) (Session, error) Login(username, password string) (Session, error) } func UserForSession(as AuthenticatorService, token string) (User, error) { session, err := as.GetSession(token) if err != nil { return nil, err } user, err := as.GetUser(session.GetUsername()) if err != nil { return nil, err } return user, nil } func New(host string) AuthenticatorService { if host == ":memory:" { return exampleMemoryUsers } return &LDAPAuthService{host} }