Documentation ¶
Index ¶
- Variables
- func HashPassword(password string) (string, error)
- type AuthStore
- type Group
- type InMemoryAuthStore
- func (s *InMemoryAuthStore) Authenticate(username, password string) (*User, error)
- func (s *InMemoryAuthStore) Authorize(user *User, role string) bool
- func (s *InMemoryAuthStore) AuthorizeGroup(user *User, group string) bool
- func (s *InMemoryAuthStore) Backup(filename string) error
- func (s *InMemoryAuthStore) CreateGroup(group *Group) error
- func (s *InMemoryAuthStore) CreateRole(role *Role) error
- func (s *InMemoryAuthStore) CreateUser(user *User) error
- func (s *InMemoryAuthStore) FindUserByEmail(email string) (*User, error)
- func (s *InMemoryAuthStore) FindUserByID(id int) (*User, error)
- func (s *InMemoryAuthStore) FindUserByUsername(username string) (*User, error)
- func (s *InMemoryAuthStore) Restore(filename string) error
- func (s *InMemoryAuthStore) UpdateRole(role *Role) error
- func (s *InMemoryAuthStore) UpdateUser(user *User) error
- type Role
- type User
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrorUserNotFound = fmt.Errorf("user not found") ErrorUserExists = fmt.Errorf("user already exists") ErrorGroupNotFound = fmt.Errorf("group not found") ErrorGroupExists = fmt.Errorf("group already exists") ErrorRoleNotFound = fmt.Errorf("role not found") ErrorRoleExists = fmt.Errorf("role already exists") ErrorUnAuthorized = fmt.Errorf("unauthorized") ErrorInvalidPassword = fmt.Errorf("invalid password") )
declare errors
Functions ¶
func HashPassword ¶
HashPassword hashes a password using bcrypt
Types ¶
type AuthStore ¶
type AuthStore interface { FindUserByID(id int) (*User, error) FindUserByUsername(username string) (*User, error) FindUserByEmail(email string) (*User, error) CreateUser(user *User) error UpdateUser(user *User) error Authenticate(username, password string) (*User, error) Authorize(user *User, role string) bool AuthorizeGroup(user *User, group string) bool }
type InMemoryAuthStore ¶
InMemoryAuthStore provides an in-memory implementation of AuthStore
func NewInMemoryAuthStore ¶
func NewInMemoryAuthStore() *InMemoryAuthStore
func NewInMemoryAuthStoreFromBackup ¶
func NewInMemoryAuthStoreFromBackup(filename string) *InMemoryAuthStore
func (*InMemoryAuthStore) Authenticate ¶
func (s *InMemoryAuthStore) Authenticate(username, password string) (*User, error)
Authenticate authenticates a user by their username and password
func (*InMemoryAuthStore) Authorize ¶
func (s *InMemoryAuthStore) Authorize(user *User, role string) bool
func (*InMemoryAuthStore) AuthorizeGroup ¶
func (s *InMemoryAuthStore) AuthorizeGroup(user *User, group string) bool
func (*InMemoryAuthStore) Backup ¶
func (s *InMemoryAuthStore) Backup(filename string) error
Backup writes the in-memory data to a file
func (*InMemoryAuthStore) CreateGroup ¶
func (s *InMemoryAuthStore) CreateGroup(group *Group) error
func (*InMemoryAuthStore) CreateRole ¶
func (s *InMemoryAuthStore) CreateRole(role *Role) error
func (*InMemoryAuthStore) CreateUser ¶
func (s *InMemoryAuthStore) CreateUser(user *User) error
func (*InMemoryAuthStore) FindUserByEmail ¶
func (s *InMemoryAuthStore) FindUserByEmail(email string) (*User, error)
func (*InMemoryAuthStore) FindUserByID ¶
func (s *InMemoryAuthStore) FindUserByID(id int) (*User, error)
func (*InMemoryAuthStore) FindUserByUsername ¶
func (s *InMemoryAuthStore) FindUserByUsername(username string) (*User, error)
func (*InMemoryAuthStore) Restore ¶
func (s *InMemoryAuthStore) Restore(filename string) error
Restore reads the in-memory data from a file
func (*InMemoryAuthStore) UpdateRole ¶
func (s *InMemoryAuthStore) UpdateRole(role *Role) error
func (*InMemoryAuthStore) UpdateUser ¶
func (s *InMemoryAuthStore) UpdateUser(user *User) error
Click to show internal directories.
Click to hide internal directories.