ginp

package module
v0.0.0-...-1b2714a Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 7 Imported by: 6

README

ginp

Documentation

Index

Constants

View Source
const (
	DebugMode   = "debug"
	ReleaseMode = "release"
	TestMode    = "test"
)
View Source
const (
	TokenExpire = 7 * 24 * time.Hour
)

Variables

View Source
var (
	TokenExpired = errors.New("token expired")
	TokenInvalid = errors.New("invalid token")
)
View Source
var (
	Engine = gin.Default()
)

Functions

func AddController

func AddController(ctl Controller) error

func Auth

func Auth(obj Controller) gin.HandlerFunc

func DisableToken

func DisableToken()

func Mode

func Mode() string

func SetEngine

func SetEngine(engine *gin.Engine)

func SetMode

func SetMode(mode string)

func SetTokenSignKey

func SetTokenSignKey(signKey string)

Types

type Claims

type Claims struct {
	*jwt.StandardClaims
	*UserInfo
}

type Controller

type Controller interface {
	Group() string
	TokenRequired(string) bool
}

type H

type H gin.H

type JWT

type JWT struct {
	SignKey []byte
}

func NewJWT

func NewJWT(key string) *JWT

func (*JWT) Create

func (j *JWT) Create(user *UserInfo) (string, error)

func (*JWT) GetKey

func (j *JWT) GetKey(token *jwt.Token) (interface{}, error)

func (*JWT) Parse

func (j *JWT) Parse(val string) (*Claims, error)

func (*JWT) Refresh

func (j *JWT) Refresh(val string) (string, error)

type Model

type Model struct {
	ID        uint64    `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"create_at" gorm:"index;not null;default:CURRENT_TIMESTAMP"`
	UpdatedAt time.Time `json:"update_at" gorm:"not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
}

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func (*Request) Bind

func (req *Request) Bind(obj interface{}) error

func (*Request) BindJSON

func (req *Request) BindJSON(obj interface{}) error

func (*Request) Context

func (req *Request) Context() *gin.Context

func (*Request) GetUserInfo

func (req *Request) GetUserInfo() *UserInfo

type Response

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

func DataResponse

func DataResponse(data interface{}) *Response

func ErrorResponse

func ErrorResponse(code int, err error) *Response

func TokenResponse

func TokenResponse(user *UserInfo, signKey string) *Response

type UserInfo

type UserInfo struct {
	Name   string   `json:"name"`
	Email  string   `json:"email"`
	Avatar string   `json:"avatar"`
	Roles  []string `json:"roles"`
}

Jump to

Keyboard shortcuts

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