app

package
v0.0.0-...-cb65031 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken(appKey, appSecret string) (string, error)

GenerateToken generates the token by given claims and HS256

func GetJWTSecret

func GetJWTSecret() []byte

func GetPage

func GetPage(c *gin.Context) int

GetPage gets the page according page field in the DB

func GetPageOffset

func GetPageOffset(page, pageSize int) int

GetPageOffset gets the offset according page and pageSize

func GetPageSize

func GetPageSize(c *gin.Context) int

GetPageSize gets the page size according page_size field in the DB

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	AppKey    string `json:"app_key"`
	AppSecret string `json:"app_secret"`
}

func ParseToken

func ParseToken(token string) (*Claims, error)

ParseToken parses given token into a tokenClaims and validates that token according Claims

type Pager

type Pager struct {
	Page      int `json:"page"`
	PageSize  int `json:"page_size"`
	TotalRows int `json:"total_rows"`
}

type Response

type Response struct {
	Ctx *gin.Context
}

Response wraps gin.Context in order to offer response processing

func NewResponse

func NewResponse(ctx *gin.Context) *Response

NewResponse returns a Response instance with given context

func (*Response) ToErrorResponse

func (r *Response) ToErrorResponse(err *errcode.Error)

ToErrorResponse converts given details into a response body with error message

func (*Response) ToResponse

func (r *Response) ToResponse(data any)

ToResponse converts any valid data into a response body

func (*Response) ToResponseList

func (r *Response) ToResponseList(list any, totalRows int)

ToResponseList converts a data list into a response list

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 any) (bool, ValidErrors)

func BindAndValidHeader

func BindAndValidHeader(c *gin.Context, v any) (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