ginger

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 29 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.数据库工具(数据库迁移,数据库填充,数据库默认创建,自动字段生成) partial yes https://github.com/gobkc/md

6.日志处理 ES,FILE支持 yes 全局注入 https://github.com/gobkc/logger

7.swagger集成 yes

8.socket和ws协议集成 no

9.grpc支持 yes

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

11.curl库支持

12.yaml库支持 https://github.com/gobkc/ginger/blob/master/config/yaml.md yes

13.阿里云短信支持 https://github.com/gobkc/ginger/blob/master/ali-sms.md yes

使用方式

export GOPROXY=https://mirrors.aliyun.com/goproxy
go mod edit -require github.com/gobkc/ginger@v0.0.9
go mod tidy
go mod vendor

DEMO LIST

curl

1.GET请求 不携带参数,并且将结果反馈给result

var result string
var err = ginger.NewCurl("http://gobk.cn:9999/").
	Token("57aaec9cbd72").
	Get().BindString(&result)

2.GET请求 携带参数(param为结构体)

var result string
var param = Param{}
param.Username = "xiong"
var err = ginger.NewCurl("http://gobk.cn:9999/").
	Token("57aaec9cbd72").
	Get(&param).BindString(&result)

3.POST请求 携带参数,并将结果返回到一个结构体

var result = UserOk{}
var param = Param{}
param.Username = "xiong"
param.Password = "123456"
var err = ginger.NewCurl("http://gobk.cn:9999/").
	Token("57aaec9cbd72").
	POST(&param).Bind(&result)

4.其余请求参考上述用法,可用BindString获取返回的字符串自行处理,也可以用Bind获取结构体,格式化为你需要的数据

5.Token方法和Auth方法同时存在只有一个起作用

6.可以用ContentType方法设置请求类型,也可以多次调用Header方法来设置多个header

Documentation

Index

Constants

View Source
const (
	//ErrNoPhoneParam 没有设置电话参数
	ErrNoPhoneParam = 1 << iota
	//ErrNoRegionParam 没有设置区域参数
	ErrNoRegionParam
	//ErrNoKeyParam 没有设置key参数
	ErrNoKeyParam
	//ErrNoSecretParam 没有设置secret参数
	ErrNoSecretParam
	//ErrNoSignNameParam 没有设置签名名称参数
	ErrNoSignNameParam
	//ErrNoTemplateCodeParam 没有设置模板代码参数
	ErrNoTemplateCodeParam
)
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 AliSMS added in v0.1.8

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

AliSMS 阿里SMS类

func NewAliSMS added in v0.1.8

func NewAliSMS() *AliSMS

NewAliSMS 初始化类

func (*AliSMS) CheckParam added in v0.1.8

func (a *AliSMS) CheckParam() (err error)

CheckParam 检查内部参数

func (*AliSMS) GetErr added in v0.1.8

func (a *AliSMS) GetErr(errCode int) error

GetErr 获取错误信息

func (*AliSMS) Send added in v0.1.8

func (a *AliSMS) Send(templateParam interface{}) (response *dysmsapi.SendSmsResponse, err error)

Send 发送短信

func (*AliSMS) SetAccessKey added in v0.1.8

func (a *AliSMS) SetAccessKey(accessKey string) *AliSMS

SetAccessKey 设置访问key

func (*AliSMS) SetAccessSecret added in v0.1.8

func (a *AliSMS) SetAccessSecret(accessSecret string) *AliSMS

SetAccessSecret 设置secret

func (*AliSMS) SetPhone added in v0.1.8

func (a *AliSMS) SetPhone(phone string) *AliSMS

SetPhone 设置发送到哪个手机

func (*AliSMS) SetRegion added in v0.1.8

func (a *AliSMS) SetRegion(region string) *AliSMS

SetRegion 设置区域

func (*AliSMS) SetSignName added in v0.1.8

func (a *AliSMS) SetSignName(signName string) *AliSMS

SetSignName 设置短信签名名称

func (*AliSMS) SetTemplateCode added in v0.1.8

func (a *AliSMS) SetTemplateCode(templateCode string) *AliSMS

SetTemplateCode 设置模板代码

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 Curl added in v0.0.8

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

func NewCurl added in v0.0.8

func NewCurl(maybeUrl ...interface{}) *Curl

新的CURL对象

func (*Curl) Auth added in v0.0.8

func (h *Curl) Auth(username string, password string) *Curl

Auth 设置auth

func (*Curl) Bind added in v0.0.8

func (h *Curl) Bind(data interface{}) error

Bind 绑定结构体

func (*Curl) BindString added in v0.0.8

func (h *Curl) BindString(data interface{}) error

绑定参数,这里的参数必须是一个字符串的地址

func (*Curl) ContentType added in v0.0.8

func (h *Curl) ContentType(contentType string) *Curl

ContentType 设置ContentType

func (*Curl) Delete added in v0.1.4

func (h *Curl) Delete(data ...interface{}) *Curl

DELETE请求

func (*Curl) Get added in v0.0.8

func (h *Curl) Get(data ...interface{}) *Curl

GET请求

func (*Curl) Head added in v0.0.8

func (h *Curl) Head(data ...interface{}) *Curl

HEAD请求

func (*Curl) Header added in v0.0.8

func (h *Curl) Header(headerKey string, headerValue string) *Curl

Header 设置header

func (*Curl) Patch added in v0.0.8

func (h *Curl) Patch(data ...interface{}) *Curl

PATCH请求

func (*Curl) Post added in v0.0.8

func (h *Curl) Post(data ...interface{}) *Curl

POST请求

func (*Curl) Put added in v0.0.8

func (h *Curl) Put(data ...interface{}) *Curl

PUT请求

func (*Curl) Token added in v0.0.8

func (h *Curl) Token(token string) *Curl

token 加密后的 和basic auth不能同时存在

func (*Curl) Url added in v0.0.8

func (h *Curl) Url(uri string) *Curl

设定要请求的URI地址

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 Headers added in v0.0.8

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

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)
}

type Orm added in v0.1.0

type Orm struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Orm mysql的orm包拓展

func NewOrm added in v0.1.0

func NewOrm() *Orm

NewOrm 返回Orm实例

func (*Orm) Register added in v0.1.0

func (o *Orm) Register() *Orm

Register 注册orm

func (*Orm) SaveAll added in v0.1.0

func (o *Orm) SaveAll(data interface{}) error

SaveAll 添加多行数据

func (*Orm) SetDbname added in v0.1.0

func (o *Orm) SetDbname(dbname string) *Orm

SetDbname 设置数据库名称

func (*Orm) SetPassword added in v0.1.0

func (o *Orm) SetPassword(password string) *Orm

SetPassword 设置密码

func (*Orm) SetPort added in v0.1.0

func (o *Orm) SetPort(port int) *Orm

SetPort 设置端口

func (*Orm) SetServer added in v0.1.0

func (o *Orm) SetServer(server string) *Orm

SetServer 设置服务器

func (*Orm) SetUser added in v0.1.0

func (o *Orm) SetUser(user string) *Orm

SetUser 设置用户名

type Pager added in v0.1.9

type Pager gorm.DB

Pager 分页继承类

func (*Pager) Page added in v0.1.9

func (p *Pager) Page(page int, pageSize int, total *int, pageNum *int) *gorm.DB

Page 分页

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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