app

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package app eagle defines something for app

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 Error

func Error(c *gin.Context, err error)

Error return a error response

func HealthCheck

func HealthCheck(c *gin.Context)

HealthCheck will return OK if the underlying BoltDB is healthy. At least healthy enough for demoing purposes.

func RouteNotFound

func RouteNotFound(c *gin.Context)

RouteNotFound 未找到相关路由

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

func Success

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

Success return a success response

Types

type App

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

App global app

func New

func New(opts ...Option) *App

New create a app globally

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 Config

type Config struct {
	Name              string
	Version           string
	Mode              string
	PprofPort         string
	URL               string
	JwtSecret         string
	JwtTimeout        int
	SSL               bool
	CtxDefaultTimeout time.Duration
	CSRF              bool
	Debug             bool
	EnableTrace       bool
	EnablePprof       bool
	HTTP              ServerConfig
	GRPC              ServerConfig
}

Config global config nolint

var (
	// Conf global app var
	Conf *Config
)

type Option

type Option func(o *options)

Option is func for application

func WithContext

func WithContext(ctx context.Context) Option

WithContext with a context

func WithEndpoint

func WithEndpoint(endpoints ...*url.URL) Option

WithEndpoint with service endpoint.

func WithID

func WithID(id string) Option

WithID with app id

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger .

func WithMetadata

func WithMetadata(md map[string]string) Option

WithMetadata with service metadata.

func WithName

func WithName(name string) Option

WithName .

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry with service registry.

func WithServer

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

WithServer with a server , http or grpc

func WithSignal

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

WithSignal with some system signal

func WithVersion

func WithVersion(version string) Option

WithVersion with a version

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"`
	Details []string    `json:"details,omitempty"`
}

Response define a response struct

func NewResponse

func NewResponse() *Response

NewResponse return a response

func (*Response) Error

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

func (*Response) Success

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

type ServerConfig

type ServerConfig struct {
	Network      string
	Addr         string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

ServerConfig server config.

type ValidError

type ValidError struct {
	Key     string
	Message string
}

ValidError .

func (*ValidError) Error

func (v *ValidError) Error() string

Error return error msg

type ValidErrors

type ValidErrors []*ValidError

ValidErrors .

func BindAndValid

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

BindAndValid valid params

func (ValidErrors) Error

func (v ValidErrors) Error() string

Error return error string

func (ValidErrors) Errors

func (v ValidErrors) Errors() []string

Errors return some error

Jump to

Keyboard shortcuts

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