manager

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const KeyToken = "manager:token:valuefirst"

KeyToken is the key to be used for storing the token.

Variables

View Source
var (
	// ErrNilClient is the error for nil client.
	ErrNilClient = errors.New("nil client")
)

Functions

This section is empty.

Types

type FnOption

type FnOption func(o *Option)

FnOption is the function to set the option.

func WithClient

func WithClient(c TokenClient) FnOption

WithClient sets the client.

func WithKey

func WithKey(key string) FnOption

WithKey sets the key.

func WithStorage

func WithStorage(s storage.Hub) FnOption

WithStorage sets the storage.

type Option

type Option struct {
	Storage storage.Hub
	Client  TokenClient
	Key     string
}

Option is the option of the manager.

func (*Option) Assign

func (o *Option) Assign(opts ...FnOption) *Option

Assign assigns the option.

func (*Option) Clone

func (o *Option) Clone() *Option

Clone clones the Option.

func (*Option) Default

func (o *Option) Default() *Option

Default sets the default option.

func (*Option) Validate

func (o *Option) Validate() (err error)

Validate validates the option.

type ResponseEnableToken

type ResponseEnableToken struct {
	Response string `json:"Response"`
}

ResponseEnableToken is the response of EnableToken.

type ResponseGenerateToken

type ResponseGenerateToken struct {
	Token string `json:"token"`

	// ExpiryDate is the expiry date of the token.
	// The format is "2022-07-10 22:32:30".
	// The time format used in this package is storage.TimeFormatExpiredDate.
	ExpiryDate string `json:"expiryDate"`
}

ResponseGenerateToken is the response of GenerateToken.

func (*ResponseGenerateToken) ToToken

func (r *ResponseGenerateToken) ToToken() (s *storage.Token, err error)

ToToken converts the ResponseGenerateToken to a Token.

type TokenClient

type TokenClient interface {
	// GenerateToken generate a token for the user.
	GenerateToken(ctx context.Context) (res ResponseGenerateToken, err error)
	// EnableToken enable the token.
	EnableToken(ctx context.Context, token string) (res ResponseEnableToken, err error)
	// DisableToken disables the token.
	DisableToken(ctx context.Context, token string) (res ResponseEnableToken, err error)
	// DeleteToken disables the token.
	DeleteToken(ctx context.Context, token string) (res ResponseEnableToken, err error)
}

TokenClient is the contract of the token client to manage token.

type TokenManager

type TokenManager interface {
	// Get gets the token from the storage.Hub.
	Get(ctx context.Context) (token string, err error)
}

TokenManager is the contract of the token manager.

func New

func New(opts ...FnOption) (tm TokenManager)

New creates a new token manager.

Jump to

Keyboard shortcuts

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