addition

package
v0.0.0-...-4de286f Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIDoc = apidoc.
	New().
	Doc(path.Join("", "doc")).
	Init(func(api *apidoc.APIDoc) {
		api.Prefix = "/docs"
		api.GORMExt = GORMExt
		api.MGOExt = MGOExt
	})

APIDoc defined apidoc for sys .Doc confg system api

View Source
var GORMExt = gormext.
	New().
	Init(func(ext *gormext.GORM) {
		cfg := &gormext.Config{}
		if err := conf.Conf.Unmarshal("sql", cfg); err != nil {
			panic(err)
		}
		ext.Conf(cfg)
		ext.DB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8")
		ext.DB.LogMode(true)
		ext.API.Opts.Prefix = "/template/gorm"
		ext.API.Opts.RouteHooks = &gormext.RouteHooks{

			List: &gormext.ListHook{
				Cond: func(cond map[string]interface{}, c *gin.Context, info struct{ Name string }) map[string]interface{} {
					iden, _ := c.Get("identify")
					if iden != nil {
						cond["CreatorID"] = iden.(*identify.Token).ExtraValue("ID")
					}
					return cond
				},
			},

			One: &gormext.OneHook{
				Cond: func(cond map[string]interface{}, c *gin.Context, info struct{ Name string }) map[string]interface{} {
					iden, _ := c.Get("identify")
					if iden != nil {
						cond["CreatorID"] = iden.(*identify.Token).ExtraValue("ID")
					}
					return cond
				},
			},

			Update: &gormext.UpdateHook{
				Cond: func(cond map[string]interface{}, c *gin.Context, info struct{ Name string }) map[string]interface{} {
					iden, _ := c.Get("identify")
					if iden != nil {
						cond["CreatorID"] = iden.(*identify.Token).ExtraValue("ID")
					}
					return cond
				},
			},

			Delete: &gormext.DeleteHook{
				Cond: func(cond map[string]interface{}, c *gin.Context, info struct{ Name string }) map[string]interface{} {
					iden, _ := c.Get("identify")
					if iden != nil {
						cond["CreatorID"] = iden.(*identify.Token).ExtraValue("ID")
					}
					return cond
				},
			},
		}
	})

GORMExt defined ext for gorm .API use default api routes .Plugin use as bulrush plugin

View Source
var I18N = addition.
	NewI18N().
	Init(func(i18n *addition.I18N) func() {
		m := &addition.M{}
		utils.LoadYaml("conf/yaml/locales.yaml", m)
		return func() {
			i18n.AddLocales(*m)
		}
	})

I18N defined i18n for sys .I18NLocale to get i18n asserts

View Source
var Logger = addition.RushLogger.
	AddTransports(
		logger.NewFileTransport(logger.Transport{
			Dirname: path.Join(path.Join(".", utils.Some(conf.Conf.Log.Path, "logs").(string)), "error"),
			Level:   logger.ERROR,
			Maxsize: logger.Maxsize,
		}),
		logger.NewFileTransport(logger.Transport{
			Dirname: path.Join(path.Join(".", utils.Some(conf.Conf.Log.Path, "logs").(string)), "combined"),
			Level:   logger.SILLY,
			Maxsize: logger.Maxsize,
		}),
	).
	Init(func(j *logger.Journal) {
		j.SetFlags((logger.LstdFlags | logger.Llongfile))
	})

Logger defined bulrush or system log global proxy Two Transport has been added 1: RotateFile 2: Console

View Source
var MGOExt = mgoext.
	New().
	Init(func(ext *mgoext.Mongo) {
		cfg := &mgo.DialInfo{}
		if err := conf.Conf.Unmarshal("mongo", cfg); err != nil {
			panic(err)
		}
		ext.Conf(cfg)
		ext.API.Opts.Prefix = "/template/mgo"
		ext.API.Opts.RouteHooks = &mgoext.RouteHooks{
			List: &mgoext.ListHook{
				Pre: func(c *gin.Context) {
					Logger.Info("all mgo before")
				},
			},
		}
	})

MGOExt defined ext for mgo .API use default api routes .Plugin use as bulrush plugin

View Source
var Redis = redisext.New().
	Init(func(r *redisext.Redis) {
		cfg := &redis.Options{}
		if err := conf.Conf.Unmarshal("redis", cfg); err != nil {
			panic(err)
		}
		r.Conf(cfg)
	})

Redis application redis store

Functions

func DialEmail

func DialEmail(ret func(m *gomail.Message) *gomail.Message) error

DialEmail defined send email

func GRPC

func GRPC(address string, opts ...grpc.DialOption) func(func(*grpc.ClientConn, context.Context) interface{}) interface{}

GRPC defined grpc call

func Request

func Request(method string, url string, payload io.Reader) (*http.Response, error)

Request defined Request global proxy

Types

This section is empty.

Jump to

Keyboard shortcuts

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