um

package
v0.0.0-...-cb66316 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 10 Imported by: 0

README

User Management module

(still under development)

go run um/migrate-gen/main.go examples/simple-todo/migrations/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateUmMigrationsFile

func CreateUmMigrationsFile(dir string) error

Types

type Config

type Config struct {
	Log         zerolog.Logger
	DB          dbdriver.DB
	SystemRoles []string
}

type GetUserParams

type GetUserParams struct {
	UseUID bool
	UID    uuid.UUID

	UseID bool
	ID    int

	UseIdentity bool
	Identity    string
}

type IRoleRepo

type IRoleRepo interface {
	Insert(ctx context.Context, conn dbdriver.DBTX, name ...string) ([]Role, error)
	Get(ctx context.Context, conn dbdriver.DBTX, id int) (Role, error)
	Select(ctx context.Context, conn dbdriver.DBTX, p RoleSelectParams) ([]Role, error)
	Delete(ctx context.Context, conn dbdriver.DBTX, id int) error
	Update(ctx context.Context, conn dbdriver.DBTX, p RoleUpdateParams) (Role, error)
	AssignRolesToUser(ctx context.Context, conn dbdriver.DBTX, p UserRoleAssignParams) error
}

type ISchema

type ISchema interface {
	Up(ctx context.Context, conn dbdriver.DBTX) error
	Down(ctx context.Context, conn dbdriver.DBTX) error
}

type IUserRepo

type IUserRepo interface {
	Insert(ctx context.Context, conn dbdriver.DBTX, p InsertUserParams) (User, error)
	Get(ctx context.Context, conn dbdriver.DBTX, p GetUserParams) (User, error)
	Select(ctx context.Context, conn dbdriver.DBTX, p SelectUserParams) ([]User, error)
	Delete(ctx context.Context, conn dbdriver.DBTX, p GetUserParams) error
	Update(ctx context.Context, conn dbdriver.DBTX, p UpdateUserParams) (User, error)
	Login(ctx context.Context, conn dbdriver.DBTX, p UserLoginParams) (User, error)
}

type InsertUserParams

type InsertUserParams struct {
	Identity string
	Passwd   string
}

type RegisterUserOpts

type RegisterUserOpts struct {
	Identity string
	Passwd   string
	Roles    []string

	BeforeCommit func(ctx context.Context, conn dbdriver.DBTX, u User) error
	AfterCommit  func(ctx context.Context, conn dbdriver.DBTX, u User) error
}

type Role

type Role struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Role the roles of the system

type RoleRepo

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

func (*RoleRepo) AssignRolesToUser

func (r *RoleRepo) AssignRolesToUser(ctx context.Context, conn dbdriver.DBTX, p UserRoleAssignParams) error

func (*RoleRepo) Delete

func (r *RoleRepo) Delete(ctx context.Context, conn dbdriver.DBTX, id int) error

func (*RoleRepo) Get

func (r *RoleRepo) Get(ctx context.Context, conn dbdriver.DBTX, id int) (Role, error)

func (*RoleRepo) Insert

func (r *RoleRepo) Insert(ctx context.Context, conn dbdriver.DBTX, name ...string) ([]Role, error)

func (*RoleRepo) Select

func (r *RoleRepo) Select(ctx context.Context, conn dbdriver.DBTX, p RoleSelectParams) ([]Role, error)

func (*RoleRepo) Update

func (r *RoleRepo) Update(ctx context.Context, conn dbdriver.DBTX, p RoleUpdateParams) (Role, error)

type RoleSelectParams

type RoleSelectParams struct {
	Ids    []int
	UseIds bool

	Names    []string
	UseNames bool
}

type RoleUpdateParams

type RoleUpdateParams struct {
	ID   int
	Name string
}

type Schema

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

func (*Schema) Down

func (s *Schema) Down(ctx context.Context, conn dbdriver.DBTX) error

func (*Schema) Up

func (s *Schema) Up(ctx context.Context, conn dbdriver.DBTX) error

type SelectUserParams

type SelectUserParams struct {
	AfterID int

	UseLimit bool
	Limit    int
}

type Service

type Service struct {
	Schema ISchema
	Roles  IRoleRepo
	Users  IUserRepo
	// contains filtered or unexported fields
}

func NewService

func NewService(cfg Config) *Service

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context, p GetUserParams) error

func (*Service) GetUserByUID

func (s *Service) GetUserByUID(ctx context.Context, uid string) (User, error)

func (*Service) InitSchema

func (s *Service) InitSchema(ctx context.Context) error

func (*Service) InsertRoles

func (s *Service) InsertRoles(ctx context.Context) error

func (*Service) Login

func (s *Service) Login(ctx context.Context, u string, p string) (User, error)

func (*Service) RegisterUser

func (s *Service) RegisterUser(ctx context.Context, p RegisterUserOpts) (User, error, error)

func (*Service) SelectUsers

func (s *Service) SelectUsers(ctx context.Context, p SelectUserParams) ([]User, error)

type UpdateUserParams

type UpdateUserParams struct {
}

type User

type User struct {
	ID        int       `json:"-"`
	UID       uuid.UUID `json:"uid"`
	Identity  string    `json:"identity"`
	EncPasswd string    `json:"-"`
	Roles     []Role    `json:"roles"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

User represents a system user

func (*User) HasAnyRole

func (o *User) HasAnyRole(roles ...string) bool

func (*User) HasRole

func (o *User) HasRole(role string) bool

type UserLoginParams

type UserLoginParams struct {
	Identity string
	Passwd   string
}

type UserRepo

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

func (*UserRepo) Delete

func (u *UserRepo) Delete(ctx context.Context, conn dbdriver.DBTX, p GetUserParams) error

func (*UserRepo) Get

func (u *UserRepo) Get(ctx context.Context, conn dbdriver.DBTX, p GetUserParams) (User, error)

func (*UserRepo) Insert

func (u *UserRepo) Insert(ctx context.Context, conn dbdriver.DBTX, p InsertUserParams) (User, error)

func (*UserRepo) Login

func (u *UserRepo) Login(ctx context.Context, conn dbdriver.DBTX, p UserLoginParams) (User, error)

func (*UserRepo) Select

func (u *UserRepo) Select(ctx context.Context, conn dbdriver.DBTX, p SelectUserParams) ([]User, error)

func (*UserRepo) Update

func (u *UserRepo) Update(ctx context.Context, conn dbdriver.DBTX, p UpdateUserParams) (User, error)

type UserRoleAssignParams

type UserRoleAssignParams struct {
	UserID int
	Roles  []Role
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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