user

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoUserInformation = errors.New("no user information")

Functions

func NewContext

func NewContext(ctx context.Context, usr User) context.Context

NewContext returns a new context.Context that carries the provided user ID.

Types

type Config

type Config struct {
	IdentityProviderDefaultName string
}

type DuplicateRecordError

type DuplicateRecordError struct {
	UUID  string
	Email string
}

func (DuplicateRecordError) Error

func (e DuplicateRecordError) Error() string

type InvalidError

type InvalidError struct {
	UUID string
}

func (InvalidError) Error

func (e InvalidError) Error() string

type NotFoundError

type NotFoundError struct {
	UUID  string
	Email string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Repository

type Repository interface {
	Create(ctx context.Context, u *User) (string, error)
	GetByEmail(ctx context.Context, email string) (User, error)
	GetByUUID(ctx context.Context, uuid string) (User, error)
	UpsertByEmail(ctx context.Context, u *User) (string, error)
}

Repository contains interface of supported methods

type Service

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

Service is a type of service that manages business process

func NewService

func NewService(logger log.Logger, repository Repository, opts ...func(*Service)) *Service

NewService initializes user service

func (*Service) ValidateUser

func (s *Service) ValidateUser(ctx context.Context, uuid, email string) (string, error)

ValidateUser checks if user uuid is already in DB if exist in DB, return user ID, if not exist in DB, create a new one

type User

type User struct {
	ID        string    `json:"-" diff:"-" db:"id"`
	UUID      string    `json:"uuid,omitempty" diff:"-" db:"uuid"`
	Email     string    `json:"email" diff:"email" db:"email"`
	Provider  string    `json:"provider" diff:"-" db:"provider"`
	CreatedAt time.Time `json:"-" diff:"-" db:"created_at"`
	UpdatedAt time.Time `json:"-" diff:"-" db:"updated_at"`
}

User is a basic entity of a user

func FromContext

func FromContext(ctx context.Context) User

FromContext returns the user ID from the context if present, and empty otherwise.

func (*User) Validate

func (u *User) Validate() error

Validate validates a user is valid or not

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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