ginger

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

ginger

Package of gin framework

使用到的包与组件

1.gin

github.com/gin-gonic/gin

2.gzip压缩

https://github.com/gin-contrib/gzip

3.swagger

github.com/swaggo/gin-swagger

Wish list

1.gzip yes

2.上传,图像裁剪,真实URL屏蔽 no

3.gin常用功能封装 yes

4.gin命令行工具 yes

5.数据库工具(数据库迁移,数据库填充,数据库默认创建,自动字段生成) no

6.日志处理 ES,FILE支持 no

7.swagger集成 yes

8.socket和ws协议集成 no

9.grpc支持 yes

10.test单元测试,基准测试快速创建工具 no

Documentation

Index

Constants

View Source
const (
	CliString = iota
	CliBool
	CliInt
)
View Source
const (
	ExplainMain = iota
	ExplainItem
)
View Source
const (
	BestCompression    = gzip.BestCompression
	BestSpeed          = gzip.BestSpeed
	DefaultCompression = gzip.DefaultCompression
	NoCompression      = gzip.NoCompression
)
View Source
const (
	HS256 = 1 << iota
	HS384
	HS512
	ES256
	ES384
	ES512
)

签名算法列表

View Source
const EXPIRED = 3600 //过期世间
View Source
const ErrBusy = "程序忙"

错误相关常量

View Source
const ErrorReLogin = "登录过期或登录错误,请重新登录"
View Source
const SECRET = "AF9-C=AF,FJN+RVV(DDD(M1a" //混淆代码 盐
View Source
const SIGNING = HS512 //签名算法

Variables

View Source
var (
	DefaultExcludedExtensions = NewExcludedExtensions([]string{
		".png", ".gif", ".jpeg", ".jpg",
	})
	DefaultOptions = &Options{
		ExcludedExtensions: DefaultExcludedExtensions,
	}
)

Functions

func Cors

func Cors() gin.HandlerFunc

func DefaultDecompressHandle

func DefaultDecompressHandle(c *gin.Context)

func Gzip

func Gzip(level int, options ...Option) gin.HandlerFunc

func Jwt added in v0.0.7

func Jwt() gin.HandlerFunc

检查JWT信息是否正确

func MakeToken added in v0.0.7

func MakeToken(claims *JWTClaims) (signedToken string, err error)

生成token

func Refresh added in v0.0.7

func Refresh(token string) (newToken string, err error)

刷新

func SignWithInfo added in v0.0.7

func SignWithInfo(claims *JWTClaims) (token string, err error)

生成签名,并携带用户信息

func ToSignMethod added in v0.0.7

func ToSignMethod(methodInt int) (sm jwt.SigningMethod)

常量转换为固定的算法

Types

type Cli added in v0.0.4

type Cli struct {
	Row        CliRow
	ExplainRow Explain
	Explains   []Explain
}
var CliIns *Cli

func GetCli added in v0.0.4

func GetCli() *Cli

单例模式获取实例

func (*Cli) Explain added in v0.0.4

func (c *Cli) Explain(info string) *Cli

func (*Cli) Item added in v0.0.4

func (c *Cli) Item(name string) *Cli

func (*Cli) Save added in v0.0.4

func (c *Cli) Save() CliInput

func (*Cli) SaveExplain added in v0.0.4

func (c *Cli) SaveExplain() bool

解析CLI命令并返回是否有说明

func (*Cli) SetBoolDefault added in v0.0.4

func (c *Cli) SetBoolDefault(d interface{}) *Cli

func (*Cli) SetDefault added in v0.0.4

func (c *Cli) SetDefault(d interface{}) *Cli

func (*Cli) SetExplainItem added in v0.0.4

func (c *Cli) SetExplainItem(info string) *Cli

func (*Cli) SetIntDefault added in v0.0.4

func (c *Cli) SetIntDefault(d interface{}) *Cli

func (*Cli) SetUsage added in v0.0.4

func (c *Cli) SetUsage(usage string) *Cli

type CliData added in v0.0.4

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

func (*CliData) GetBool added in v0.0.4

func (c *CliData) GetBool() bool

func (*CliData) GetInt added in v0.0.4

func (c *CliData) GetInt() int

func (*CliData) GetString added in v0.0.4

func (c *CliData) GetString() string

type CliInput added in v0.0.4

type CliInput interface {
	GetInt() int
	GetString() string
	GetBool() bool
}

type CliRow added in v0.0.4

type CliRow struct {
	Name    string
	Type    int
	Default interface{}
	UseAge  string
}

type ExcludedExtensions

type ExcludedExtensions map[string]bool

Using map for better lookup performance

func NewExcludedExtensions

func NewExcludedExtensions(extensions []string) ExcludedExtensions

func (ExcludedExtensions) Contains

func (e ExcludedExtensions) Contains(target string) bool

type ExcludedPaths

type ExcludedPaths []string

func NewExcludedPaths

func NewExcludedPaths(paths []string) ExcludedPaths

func (ExcludedPaths) Contains

func (e ExcludedPaths) Contains(requestURI string) bool

type Explain added in v0.0.4

type Explain struct {
	Info string
	Type int
}

type GRPCContainer added in v0.0.6

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

func (*GRPCContainer) New added in v0.0.6

func (g *GRPCContainer) New(addr string) *GRPCContainer

func (*GRPCContainer) Register added in v0.0.6

func (g *GRPCContainer) Register(server *interface{})

type Ginger

type Ginger struct {
	App *gin.Engine
	// contains filtered or unexported fields
}
var IGinger *Ginger

func GetIns

func GetIns() *Ginger

单例模式获取实例

func (*Ginger) Debug

func (g *Ginger) Debug(isDebug bool) *Ginger

默认就是DEBUG。如果设置为FALSE,则ReleaseMode

func (*Ginger) GetHTTPServeMux added in v0.0.6

func (g *Ginger) GetHTTPServeMux() *http.ServeMux

func (*Ginger) LoadRouter

func (g *Ginger) LoadRouter(router func(router *gin.Engine) gin.IRoutes) *Ginger

加载路由

func (*Ginger) Run added in v0.0.6

func (g *Ginger) Run(addr string, f ...func(server *grpc.Server)) (err error)

func (*Ginger) Start

func (g *Ginger) Start(addr string)

开启服务

func (*Ginger) Swagger added in v0.0.4

func (g *Ginger) Swagger(openSwagger bool) *Ginger

开启swagger

type JWTClaims added in v0.0.7

type JWTClaims struct {
	jwt.StandardClaims
	UserID     uint   `json:"user_id"`
	Username   string `json:"username"`
	IsRealName int    `json:"is_real_name"`
	Type       int    `json:"type"`
}

定义一个结构体,用于携带额外的信息

func Verify added in v0.0.7

func Verify(token string) (claims *JWTClaims, err error)

验证TOKEN是否正确或则过期

type Option

type Option func(*Options)

func WithDecompressFn

func WithDecompressFn(decompressFn func(c *gin.Context)) Option

func WithExcludedExtensions

func WithExcludedExtensions(args []string) Option

func WithExcludedPaths

func WithExcludedPaths(args []string) Option

type Options

type Options struct {
	ExcludedExtensions ExcludedExtensions
	ExcludedPaths      ExcludedPaths
	DecompressFn       func(c *gin.Context)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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