service

package
v0.0.0-...-71c93ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cookie struct {
	// contains filtered or unexported fields
}

Cookie represents a cookie service.

func NewCookie

func NewCookie(cookieStore *securecookie.SecureCookie, logger log.Logger) *Cookie

NewCookie creates a new Cookie service.

func (*Cookie) AddFlashMessage

func (s *Cookie) AddFlashMessage(w http.ResponseWriter, r *http.Request, flashMessage FlashMessage) error

AddFlashMessage stores a new FlashMessage in a cookie.

func (*Cookie) DeleteSessionUser

func (s *Cookie) DeleteSessionUser(w http.ResponseWriter)

DeleteSessionUser deletes a SessionUser from a cookie.

func (*Cookie) FlashError

func (s *Cookie) FlashError(w http.ResponseWriter, r *http.Request, path string, err error, msg string, args ...interface{})

FlashError sets up a temporary session message for an error.

func (*Cookie) FlashMessage

func (s *Cookie) FlashMessage(w http.ResponseWriter, r *http.Request, path, msg string, args ...interface{})

FlashMessage sets up a temporary session message.

func (*Cookie) GetFlashMessages

func (s *Cookie) GetFlashMessages(w http.ResponseWriter, r *http.Request) ([]FlashMessage, error)

GetFlashMessages retrieves a slice of FlashMessage objects from a cookie and deletes it.

func (*Cookie) GetSessionUser

func (s *Cookie) GetSessionUser(r *http.Request) (repo.SessionUser, error)

GetSessionUser retrieves a SessionUser from a cookie.

func (*Cookie) StoreSessionUser

func (s *Cookie) StoreSessionUser(w http.ResponseWriter, sessionUser repo.SessionUser)

StoreSessionUser stores a SessionUser in a cookie.

type File

type File struct {
	// contains filtered or unexported fields
}

File is a service that provides file-related operations.

func NewFile

func NewFile(fileRepo FileRepo, store FileSystem, logger log.Logger) *File

NewFile creates a new File service.

func (*File) Get

func (f *File) Get(ctx context.Context, name string) (repo.FileModel, error)

Get retrieves a file model.

func (*File) List

func (f *File) List(ctx context.Context, access []string, isAdmin bool) (repo.FileModels, error)

List lists files.

func (*File) Retrieve

func (f *File) Retrieve(ctx context.Context, name string, access []string) ([]byte, error)

Retrieve retrieves the content of a file by name.

func (*File) Upload

func (f *File) Upload(ctx context.Context, name string, content []byte, access []string) (repo.FileModel, error)

Upload uploads a file with the given name and content.

type FileRepo

type FileRepo interface {
	Get(ctx context.Context, name string) (repo.FileModel, error)
	List(ctx context.Context) (repo.FileModels, error)
	Create(ctx context.Context, name string, access []string) (repo.FileModel, error)
}

type FileSystem

type FileSystem interface {
	Write(ctx context.Context, name string, data []byte) error
	Read(ctx context.Context, name string) ([]byte, error)
}

type FlashMessage

type FlashMessage struct {
	Level   Level
	Message string
}

FlashMessage represents a message to be displayed to the user.

type Level

type Level string
const (
	LevelInfo  Level = "info"
	LevelError Level = "error"
)

type PasswordChecker

type PasswordChecker interface {
	IsOK(ctx context.Context, password string) error
}

type PasswordHasher

type PasswordHasher interface {
	Check(ctx context.Context, password, hashedPassword string) error
	Hash(ctx context.Context, password string) (string, error)
}

type SessionRepo

type SessionRepo interface {
	Get(ctx context.Context, name string) (repo.SessionUser, error)
	Start(ctx context.Context, name string, isAdmin bool, access []string) (repo.SessionUser, error)
	CleanUp(ctx context.Context) error
}

type User

type User struct {
	// contains filtered or unexported fields
}

User is a service that provides user-related operations.

func NewUser

func NewUser(userRepo UserRepo, passwordHasher PasswordHasher, passwordChecker PasswordChecker, logger log.Logger) *User

NewUser creates a new User service.

func (*User) CheckPassword

func (u *User) CheckPassword(ctx context.Context, userName, password string) error

CheckPassword checks if the given username and password are correct.

func (*User) CheckPasswordHash

func (u *User) CheckPasswordHash(ctx context.Context, password, hash string) error

CheckPasswordHash checks if the given hash is a valid hash for a given password.

func (*User) Create

func (u *User) Create(ctx context.Context, name, email, password string, isAdmin bool, access []string) (repo.UserModel, error)

Create creates a new user. It hashes the password and stores the user in the repository. It also checks if the raw password is OK.

func (*User) Delete

func (u *User) Delete(ctx context.Context, name string) error

Delete deletes a user.

func (*User) Demote

func (u *User) Demote(ctx context.Context, name string) (repo.UserModel, error)

Demote demotes a user from an admin.

func (*User) HashPassword

func (u *User) HashPassword(ctx context.Context, password string) (string, error)

HashPassword hashes a given password.

func (*User) List

func (u *User) List(ctx context.Context) (repo.UserModels, error)

List lists all users.

func (*User) Login

func (u *User) Login(ctx context.Context, userName, password string) (repo.SessionUser, error)

Login logs in a user with the given username and password and returns a session hash.

func (*User) Promote

func (u *User) Promote(ctx context.Context, name string) (repo.UserModel, error)

Promote promotes a user to an admin.

func (*User) UpdateAccess

func (u *User) UpdateAccess(ctx context.Context, name string, access []string) (repo.UserModel, error)

UpdateAccess updates the access of a user.

func (*User) UpdatePassword

func (u *User) UpdatePassword(ctx context.Context, name, password string) (repo.UserModel, error)

UpdatePassword updates the password of a user.

type UserRepo

type UserRepo interface {
	Get(ctx context.Context, name string) (repo.UserModel, error)
	List(ctx context.Context) (repo.UserModels, error)
	Create(ctx context.Context, name, email, password string, isAdmin bool, access []string) (repo.UserModel, error)
	UpdatePassword(ctx context.Context, name, password string) (repo.UserModel, error)
	UpdateAccess(ctx context.Context, name string, access []string) (repo.UserModel, error)
	Promote(ctx context.Context, name string) (repo.UserModel, error)
	Demote(ctx context.Context, name string) (repo.UserModel, error)
	Delete(ctx context.Context, name string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL