app

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingHeader means the `Authorization` header was empty.
	ErrMissingHeader = errors.New("the length of the `Authorization` header is zero")
)

Functions

func Sign

func Sign(ctx context.Context, payload map[string]interface{}, secret string, timeout int64) (tokenString string, err error)

Sign signs the payload with the specified secret. The token content. iss: (Issuer)签发者 iat: (Issued At)签发时间,用Unix时间戳表示 exp: (Expiration Time)过期时间,用Unix时间戳表示 aud: (Audience)接收该JWT的一方 sub: (Subject)该JWT的主题 nbf: (Not Before)不要早于这个时间 jti: (JWT ID)用于标识JWT的唯一ID

Types

type App

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

func New

func New(c *conf.Config, opts ...Option) *App

func (*App) Run

func (a *App) Run() error

Run start app

func (*App) Stop

func (a *App) Stop() error

Stop stops the application gracefully.

type Option

type Option func(o *options)

Option is func for application

func Server

func Server(srv ...transport.Server) Option

func WithID

func WithID(id string) Option

WithID with app id

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger .

func WithName

func WithName(name string) Option

WithName .

func WithSignal

func WithSignal(sigs ...os.Signal) Option

WithSignal .

func WithVersion

func WithVersion(version string) Option

WithVersion .

type Payload

type Payload struct {
	UserID uint64
}

Payload is the data of the JSON web token.

func Parse

func Parse(tokenString string, secret string) (*Payload, error)

Parse validates the token with the specified secret, and returns the payloads if the token was valid.

func ParseRequest

func ParseRequest(c *gin.Context) (*Payload, error)

ParseRequest gets the token from the header and pass it to the Parse function to parses the token.

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func NewResponse

func NewResponse() *Response

func (*Response) Error

func (r *Response) Error(c *gin.Context, err *errcode.Error)

func (*Response) Success

func (r *Response) Success(c *gin.Context, data interface{})

type ValidError

type ValidError struct {
	Key     string
	Message string
}

func (*ValidError) Error

func (v *ValidError) Error() string

type ValidErrors

type ValidErrors []*ValidError

func BindAndValid

func BindAndValid(c *gin.Context, v interface{}) (bool, ValidErrors)

func (ValidErrors) Error

func (v ValidErrors) Error() string

func (ValidErrors) Errors

func (v ValidErrors) Errors() []string

Jump to

Keyboard shortcuts

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