Documentation

Index

Constants

This section is empty.

Variables

var Captcha = captcha.
	New().
	Init(func(c *captcha.Captcha) {
		c.Secret = "7658388"
		c.URLPrefix = "/captcha"
	})

Captcha plugin init


var Delivery = delivery.New()

Delivery Upload, Logger, Captcha Plugin init


var Identify = identify.
	New().
	AddOptions(identify.FakeURLsOption([]string{`^/api/ignore$`, `^/api/gorm/mock`})).
	AddOptions(identify.FakeTokensOption([]string{})).
	AddOptions(identify.ModelOption(&identify.RedisModel{
		Redis: addition.Redis,
	})).
	Init(func(iden *identify.Identify) {
		iden.AddOptions(
			identify.AuthOption(func(ctx *gin.Context) (interface{}, error) {
				login := struct {
					UserName string `form:"username" json:"username" xml:"username" binding:"required"`
					Password string `form:"password" json:"password" xml:"password" binding:"required"`
					Type     string `form:"type" json:"type" xml:"type"`
				}{}

				if err := ctx.ShouldBind(&login); err != nil {
					return nil, err
				}
				user := addition.GORMExt.Var("User")
				if err := addition.GORMExt.DB.Find(user, map[string]interface{}{"name": login.UserName, "password": login.Password}).Error; err != nil {
					return nil, errors.New("user authentication failed")
				}
				return user, nil
			}),
		)
	})

Identify plugin init


var Limit = &limit.Limit{
	Frequency: &limit.Frequency{
		Passages: []string{},
		Rules: []limit.Rule{
			limit.Rule{
				Methods: []string{"GET"},
				Match:   "/api/v1/user*",
				Rate:    15,
			},
			limit.Rule{
				Methods: []string{"GET"},
				Match:   "/api/v1/role*",
				Rate:    5,
			},
		},
		Model: &limit.RedisModel{
			Redis: addition.Redis,
		},
	},
}

Limit Plugin init


var Logger = &logger.Logger{
	Path: "logs",
	Format: func(p *logger.Payload, ctx *gin.Context) (f string) {
		if p.Type == logger.INT {
			startTime := time.Unix(p.StartUnix, 0).Format("2006/01/02 15:04:05")
			f = fmt.Sprintf("[%v bulrush] => %s %6s %s", startTime, p.IP, p.Method, p.URL)
		} else if p.Type == logger.OUT {
			endOfTime := time.Unix(p.EndUnix, 0).Format("2006/01/02 15:04:05")
			latency := float64(time.Unix(p.EndUnix, 0).Sub(time.Unix(p.StartUnix, 0)) / time.Millisecond)
			f = fmt.Sprintf("[%v bulrush] <= %.2fms %s %6s %s", endOfTime, latency, p.IP, p.Method, p.URL)
		}
		return
	},
}

Logger Plugin init


var MQ = mq.New()

MQ plugin init


var OpenAPI = &openapi.OpenAPI{
	URLPrefix: "/gateway",
	Auth: func(appid string) (*openapi.AppInfo, error) {
		return &openapi.AppInfo{
			AppID: "xxx",

			PublicKey: "" /* 224 byte string literal not displayed */,

			PrivateKey: "" /* 829 byte string literal not displayed */,
		}, nil
	},
}

OpenAPI Plugin init


var Proxy = &proxy.Proxy{
	Host:  "https://www.baidu.com",
	Match: "^/proxy",
	Map: func(reqPath string) string {
		return reqPath
	},
}

Proxy Plugin init


var Role = &role.Role{
	RoleHandler: func(c *gin.Context, action string) bool {
		actions := role.TransformAction(action)
		addition.Logger.Debug("actions: %s\n", actions)
		return true
	},
}

Role plugin init


var Upload = upload.New()

Upload Plugin init


Functions

This section is empty.

Types

This section is empty.