README

Directories

Snapshot

[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:237: ================================
[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:238: App: bulrush-template
[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:239: Env: local
[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:240: Http Listen on :8080
[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:241: Grpc Listen on :8081
[BUL-debug] 2019/09/22 20:31:46 /bulrush/plugin.go:242: ================================

Benchmarks

Running 3s test @ http://127.0.0.1:3333/api/v1/
8 threads and 50 connections
Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   374.51us  504.86us   8.45ms   89.96%
    Req/Sec    22.71k     4.36k   60.90k    97.94%
549392 requests in 3.10s, 77.02MB read
Requests/sec: 177249.36
Transfer/sec:     24.85MB

Instruction

Bulrush flash

Quickly build applications and customize special functions through plug-ins, Multiple base plug-ins are provided Install Bulrush

$ go get github.com/2637309949/bulrush

QuickStart

import (
    "github.com/2637309949/bulrush"
)
// Use attachs a global Recovery middleware to the router
// Use attachs a Recovery middleware to the user router
// Use attachs a LoggerWithWriter middleware to the user router
app := bulrush.Default()
app.Config(CONFIGPATH)
app.Inject("bulrushApp")
app.Use(&models.Model{}, &routes.Route{})
app.Use(func(testInject string, router *gin.RouterGroup) {
    router.GET("/bulrushApp", func (c *gin.Context) {
        c.JSON(http.StatusOK, gin.H{
            "message": 	testInject,
        })
    })
})
app.Run()

OR

import (
    "github.com/2637309949/bulrush"
)
// No middlewares has been attached
app := bulrush.New()
app.Config(CONFIGPATH)
app.Run(func(httpProxy *gin.Engine, config *bulrush.Config) {
    httpProxy.Run(config.GetString("port", ":8080"))
})

For more details, Please reference to bulrush-template.

API

Set app config

app.Config(CONFIGPATH)

Inject your custom injects

All injects would be provided as plugins params next by next.
Init injects by Inject function

app.Inject("bulrushApp")

Set injects by plugin ret

// Plugin for role
func (role *Role) Plugin() *Role {
	return role
}

Import your plugins

app.Use(func(testInject string, router *gin.RouterGroup) {
    router.GET("/bulrushApp", func (c *gin.Context) {
        c.JSON(http.StatusOK, gin.H{
            "message": 	testInject,
        })
    })
})

Run app

app.Run(func(httpProxy *gin.Engine, config *bulrush.Config) {
    port := config.GetString("port", ":8080")
    port = strings.TrimSpace(port)
    name := config.GetString("name", "")
    if prefix := port[:1]; prefix != ":" {
        port = fmt.Sprintf(":%s", port)
    }
    fmt.Println("\n\n================================")
    fmt.Printf("App: %s\n", name)
    fmt.Printf("Listen on %s\n", port)
    fmt.Println("================================")
    httpProxy.Run(port)
})

Share state between plug-ins

store state

app.Use(func(status *bulrush.Status) {
    status.Set("count", 1)
})

read state

app.Use(func(status *bulrush.Status) {
    status.Get("count")
    status.ALL()
})

Plug in communication between plug-ins

app.Use(func(events events.EventEmmiter) {
	events.On("hello", func(payload ...interface{}) {
		message := payload[0].(string)
		fmt.Println(message)
	})
})

Design Philosophy

Injects

Built-in Injects

EventEmmiter

The entire architecture in the system is developed around plug-ins, and communication between plug-ins is done through EventEmmiter, This ensures low coupling between plug-ins

Use:

// Emiter
// @Summary Task测试
// @Description Task测试
// @Tags TASK
// @Accept mpfd
// @Produce json
// @Param accessToken query string true "令牌"
// @Success 200 {string} json "{"message": "ok"}"
// @Failure 400 {string} json "{"message": "failure"}"
// @Router /mgoTest [get]
func calltask(router *gin.RouterGroup, event events.EventEmmiter) {
	router.GET("/calltask", func(c *gin.Context) {
		event.Emit("reminderEmails", "hello 2019")
		c.JSON(http.StatusOK, gin.H{"message": "ok"})
	})
}

// Listener
func RegisterHello(job *bulrush.Jobrunner, emmiter events.EventEmmiter) {
	emmiter.On("reminderEmails", func(payload ...interface{}) {
		message := payload[0].(string)
		job.Schedule("0/5 * * * * ?", reminderEmails{message})
	})
}
*Status
If you don't need database or REIDS persistence, you can achieve state consistency between plug-ins by  

sharing state

// Write state
func RegisterHello(status *bulrush.Status, emmiter events.EventEmmiter) {
	status.Set("test", 250)
}
// Read state
func RegisterHello(status *bulrush.Status, emmiter events.EventEmmiter) {
	data, _ := status.Get("test")
}
*Validate
At the same time provides with gin. Bind the same validator. V9
count := reflect.ValueOf(binds).Elem().Len()
for count > 0 {
    count = count - 1
    ele := reflect.ValueOf(binds).Elem().Index(count).Interface()
    err := validate.Struct(ele)
    if err != nil {
        c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
        return
    }
}
*Jobrunner
If you need some lightweight scheduling, you can consider this plug-in
type reminderEmails struct {
	message string
}

func (e reminderEmails) Run() {
	addition.Logger.Info("Every 5 sec send reminder emails \n")
}

// RegisterHello defined hello task
func RegisterHello(job *bulrush.Jobrunner, emmiter events.EventEmmiter) {
	emmiter.On("reminderEmails", func(payload ...interface{}) {
		message := payload[0].(string)
		job.Schedule("0/5 * * * * ?", reminderEmails{message})
	})
}
  • *ReverseInject If you don't know what plug-ins acceptor need injection content, then you can use *ReverseInject to deal with
// Model register
// Make sure all models are initialized here
var Model = func(router *gin.RouterGroup, ri *bulrush.ReverseInject) {
	ri.Register(nosql.RegisterUser)
	ri.Register(nosql.RegisterPermission)
	ri.Register(sql.RegisterProduct)
}

Plugins

Built-in Plugins

Custom your plugins

If your want to write a user-defined plugins, you should implement the plugin duck type, interface{} is a function, and you can get all you want through func parameters, also you can return any type as Injects entity.

type myPlugin interface{} { Plugin(...interface{}) interface{} }

EXAMPLE:

type Override struct {}
func (pn *Override) Plugin(router *gin.RouterGroup, httpProxy *gin.Engine) string {
    return "inject entity"
}
app.Use(&Override{})

OR

type Override struct {}
func (pn Override) Plugin(router *gin.RouterGroup, httpProxy *gin.Engine) string {
    return "inject entity"
}
app.Use(Override{})

OR

var Override = func(testInject string, router *gin.RouterGroup) string {
    return "inject entity"
}
app.Use(Override)

Assemble your plugin` config from bulrush Injects

// Example for my mgo
type conf struct {
	Addrs          []string      `json:"addrs" yaml:"addrs"`
	Timeout        time.Duration `json:"timeout" yaml:"timeout"`
	Database       string        `json:"database" yaml:"database"`
	ReplicaSetName string        `json:"replicaSetName" yaml:"replicaSetName"`
	Source         string        `json:"source" yaml:"source"`
	Service        string        `json:"service" yaml:"service"`
	ServiceHost    string        `json:"serviceHost" yaml:"serviceHost"`
	Mechanism      string        `json:"mechanism" yaml:"mechanism"`
	Username       string        `json:"username" yaml:"username"`
	Password       string        `json:"password" yaml:"password"`
	PoolLimit      int           `json:"poolLimit" yaml:"poolLimit"`
	PoolTimeout    time.Duration `json:"poolTimeout" yaml:"poolTimeout"`
	ReadTimeout    time.Duration `json:"readTimeout" yaml:"readTimeout"`
	WriteTimeout   time.Duration `json:"writeTimeout" yaml:"writeTimeout"`
	AppName        string        `json:"appName" yaml:"appName"`
	FailFast       bool          `json:"failFast" yaml:"failFast"`
	Direct         bool          `json:"direct" yaml:"direct"`
	MinPoolSize    int           `json:"minPoolSize" yaml:"minPoolSize"`
	MaxIdleTimeMS  int           `json:"maxIdleTimeMS" yaml:"maxIdleTimeMS"`
}
func New(bulCfg *bulrush.Config) *Mongo {
	conf := &conf{}
	err := bulCfg.Unmarshal("mongo", conf)
	if err != nil {
		panic(err)
	}
	session := createSession(conf)
	mgo := &Mongo{
		m:       make([]map[string]interface{}, 0),
		cfg:     conf,
		API:     &api{},
		Session: session,
	}
	mgo.API.mgo = mgo
	mgo.AutoHook = autoHook(mgo)
	return mgo
}
// Read part and assemble
func (c *Config) Unmarshal(fieldName string, v interface{}) error

Note

Note go vendor, bulrush needs to reference the same package, otherwise injection fails

MIT License

Copyright (c) 2018-2020 Double

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Expand ▾ Collapse ▴

Documentation

Index

Constants

View Source
const (
	// DebugMode indicates bul mode is debug.
	DebugMode = "debug"
	// ReleaseMode indicates bul mode is release.
	ReleaseMode = "release"
	// TestMode indicates bul mode is test.
	TestMode = "test"
)

Variables

View Source
var (
	// ErrPlugin is used when bul.Use().
	ErrPlugin = &Error{Code: uint64(100)}
	// ErrInject is used when bul.Inject() fails.
	ErrInject = &Error{Code: uint64(101)}
	// ErrUnaddressable unaddressable value
	ErrUnaddressable = &Error{Code: uint64(102)}
	// ErrPrivate indicates a private error.
	ErrPrivate = &Error{Code: uint64(103)}
	// ErrPublic indicates a public error.
	ErrPublic = &Error{Code: uint64(104)}
	// ErrNotMatch indicates not match error.
	ErrNotMatch = &Error{Code: uint64(105)}
	// ErrAny indicates any other error.
	ErrAny = &Error{Code: uint64(106)}
	// ErrNu indicates any other error.
	ErrNu = &Error{Code: uint64(107)}
)
View Source
var (
	EventsStarting = EventName(utils.ToString(1<<49 + 0))
	EventsRunning  = EventName(utils.ToString(1<<49 + 1))
	EventsShutdown = EventName(utils.ToString(1<<49 + 2))
)

Events defined built-in events

View Source
var (
	// Starting defined before all plugin
	Starting = func(event events.EventEmmiter) {
		event.Emit(EventsStarting, EventsStarting)
	}
	// Recovery system rec from panic
	Recovery = func(httpProxy *gin.Engine, router *gin.RouterGroup) {
		httpProxy.Use(recovery())
		router.Use(recovery())
	}
	// HTTPProxy create http proxy
	HTTPProxy = func() *gin.Engine {
		return gin.New()
	}
	// GRPCProxy create grpc proxy
	GRPCProxy = func() *grpc.Server {
		return grpc.NewServer()
	}
	// HTTPRouter create http router
	HTTPRouter = func(httpProxy *gin.Engine, config *Config) *gin.RouterGroup {
		return httpProxy.Group(config.Prefix)
	}
	// Override http methods
	Override = func(router *gin.RouterGroup, httpProxy *gin.Engine) {
		funk.ForEach([]func(...gin.HandlerFunc) gin.IRoutes{router.Use, httpProxy.Use}, func(Use func(...gin.HandlerFunc) gin.IRoutes) {
			Use(func(c *gin.Context) {
				if c.Request.Method != "POST" {
					c.Next()
				} else {
					method := c.PostForm("_method")
					methods := [3]string{"DELETE", "PUT", "PATCH"}
					if method != "" {
						for _, target := range methods {
							if target == strings.ToUpper(method) {
								c.Request.Method = target
								httpProxy.HandleContext(c)
								break
							}
						}
					}
				}
			})
		})
	}
	// HTTPBooting run http proxy and grpc proxy
	HTTPBooting = func(lifecycle Lifecycle, httpProxy *gin.Engine, gs *grpc.Server, event events.EventEmmiter, config *Config) {
		var err error
		defer func() {
			if err != nil {
				rushLogger.Error(fmt.Sprintf("%v", err))
			}
		}()
		addr1 := fixedPortPrefix(strings.TrimSpace(config.Port))
		addr2 := fixedPortPrefix(strings.TrimSpace(config.Port), 1)
		name := config.Name
		grpc, err := net.Listen("tcp", addr2)
		http := &http.Server{Addr: addr1, Handler: httpProxy}
		lifecycle.Append(Hook{
			OnStart: func(ctx context.Context) error {
				go func() {
					err = http.ListenAndServe()
					if err != nil {
						rushLogger.Error(fmt.Sprintf("%v", err))
					}
				}()
				go func() {
					err = gs.Serve(grpc)
					if err != nil {
						rushLogger.Error(fmt.Sprintf("%v", err))
					}
				}()
				rushLogger.Debug("================================")
				rushLogger.Debug("App: %s", name)
				rushLogger.Debug("Env: %s", config.Env)
				rushLogger.Debug("Http Listen on %s", addr1)
				rushLogger.Debug("Grpc Listen on %s", addr2)
				rushLogger.Debug("================================")
				return nil
			},
			OnStop: func(ctx context.Context) (err error) {
				gs.GracefulStop()
				http.Shutdown(ctx)
				return
			},
		})
	}

	// HTTPTLSBooting run http proxy and grpc proxy
	HTTPTLSBooting = func(lifecycle Lifecycle, httpProxy *gin.Engine, gs *grpc.Server, event events.EventEmmiter, config *Config) {
		var err error
		defer func() {
			if err != nil {
				rushLogger.Error(fmt.Sprintf("%v", err))
			}
		}()
		addr1 := fixedPortPrefix(strings.TrimSpace(config.Port))
		addr2 := fixedPortPrefix(strings.TrimSpace(config.Port), 1)
		name := config.Name
		grpc, err := net.Listen("tcp", addr2)
		http := &http.Server{Addr: addr1, Handler: httpProxy}
		lifecycle.Append(Hook{
			OnStart: func(ctx context.Context) error {
				go func() {
					err = http.ListenAndServeTLS(config.TLS.CRT, config.TLS.Key)
					if err != nil {
						rushLogger.Error(fmt.Sprintf("%v", err))
					}
				}()
				go func() {
					err = gs.Serve(grpc)
					if err != nil {
						rushLogger.Error(fmt.Sprintf("%v", err))
					}
				}()
				rushLogger.Debug("================================")
				rushLogger.Debug("App: %s", name)
				rushLogger.Debug("Env: %s", config.Env)
				rushLogger.Debug("Http Listen on %s", addr1)
				rushLogger.Debug("Grpc Listen on %s", addr2)
				rushLogger.Debug("================================")
				return nil
			},
			OnStop: func(ctx context.Context) (err error) {
				gs.GracefulStop()
				err = http.Shutdown(&HTTPContext{
					DeadLineTime: time.Now().Add(3 * time.Second),
					Chan:         make(chan struct{}, 1),
				})
				return
			},
		})
	}
	// Running defined after all plugin
	Running = func(event events.EventEmmiter) {
		event.Emit(EventsRunning, EventsRunning)
	}
)
	 Recovery         plugin   defined sys recovery
  HTTPProxy        plugin   defined http proxy
  HTTPRouter       plugin   defined http router
  Override         plugin   defined method override
  Run   plugin   defined httpproxy run
View Source
var Version = 1.0

Version defined bulrush current version

Functions

func CatchError

func CatchError(funk interface{}) (err error)

CatchError defined catch error from panic

func ErrCode

func ErrCode(err error) (code uint64)

ErrCode defined return error code

func ErrMsgs

func ErrMsgs(err error) []string

ErrMsgs defined split wrap msg

func ErrWith

func ErrWith(err *Error, msg string) error

ErrWith defined wrap error

func EventName

func EventName(name string) events.EventName

EventName defined bulrush events name

func GetLogger

func GetLogger() *logger.Journal

GetLogger defined get logger for bulrush you can append transport to addition.RushLogger It is not recommended to create new one Journal I recommendation to customize different output from addition.RushLogger, but not SetLogger

func IsDebugging

func IsDebugging() bool

IsDebugging returns true if the framework is running in debug mode. Use SetMode(gin.ReleaseMode) to disable debug mode.

func Mode

func Mode() string

Mode returns currently gin mode.

func SetLogger

func SetLogger(logger *logger.Journal)

SetLogger defined set logger for bulrush you can append transport to addition.RushLogger It is not recommended to create new one Journal I recommendation to customize different output from addition.RushLogger, but not SetLogger

func SetMode

func SetMode(value string)

SetMode sets gin mode according to input string.

func WithStack

func WithStack(err error) string

WithStack error stack

Types

type Bulrush

type Bulrush interface {
	On(events.EventName, ...events.Listener)
	Once(events.EventName, ...events.Listener)
	Emit(events.EventName, ...interface{})
	PreUse(...interface{}) Bulrush
	Use(...interface{}) Bulrush
	PostUse(...interface{}) Bulrush
	Config(string) Bulrush
	Inject(...interface{}) Bulrush
	Acquire(reflect.Type) interface{}
	Wire(interface{}) error
	Inspect()
	ToJSON() interface{}
	GET(string, ...gin.HandlerFunc) Bulrush
	POST(string, ...gin.HandlerFunc) Bulrush
	DELETE(string, ...gin.HandlerFunc) Bulrush
	PUT(string, ...gin.HandlerFunc) Bulrush
	Run(...interface{}) error
	RunTLS(...interface{}) error
	ExecWithBooting(interface{}) error
	Shutdown() error
}

Bulrush interface{} defined all framework should be , also sys provide a default Bulrush - `rush`

func Default

func Default(opt ...Option) Bulrush

Default returns an Bulrush instance with the Override and Recovery middleware already attached. --Recovery middle has been register in httpProxy and user router --Override middles has been register in router for override req

func New

func New(opt ...Option) Bulrush

New returns a new blank Bulrush instance without any middleware attached. By default the configuration is: --config json or yaml config for bulrush --injects struct instance can be reflect by bulrush --middles some middles for gin self

type Config

type Config struct {
	Version float64 `json:"version" yaml:"version"`
	Name    string  `json:"name" yaml:"name"`
	Prefix  string  `json:"prefix" yaml:"prefix"`
	Port    string  `json:"port" yaml:"port"`
	TLS     struct {
		CRT string `json:"crt" yaml:"crt"`
		Key string `json:"key" yaml:"key"`
	} `json:"tls" yaml:"tls"`
	Mode string `json:"mode" yaml:"mode"`
	Env  string `json:"env" yaml:"env"`

	Log struct {
		Level string `json:"level" yaml:"level"`
		Path  string `json:"path" yaml:"path"`
	}
	// contains filtered or unexported fields
}

Config bulrush config struct

func LoadConfig

func LoadConfig(path string) *Config

LoadConfig loads the bulrush tool configuration

func (*Config) Unmarshal

func (c *Config) Unmarshal(field string, v interface{}) (err error)

Unmarshal defined Unmarshal type

func (*Config) UnmarshalByType

func (c *Config) UnmarshalByType(data []byte, v interface{}, dataType cfgType) (err error)

UnmarshalByType defined unmarshal by diff file type

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

ConfigOption defined cfg option

func ConfigValidOption

func ConfigValidOption(path string) ConfigOption

ConfigValidOption defined Option of valid

func ParseConfigOption

func ParseConfigOption(conf *Config) ConfigOption

ParseConfigOption defined Option of PrePlugin

type Error

type Error struct {
	Err  error
	Code uint64
	Meta interface{}
}

Error represents a error's specification.

func ErrOut

func ErrOut(err error) (bulError *Error, ok bool)

ErrOut defined unwrap error

func (*Error) Error

func (msg *Error) Error() (message string)

Error implements the error interface.

func (*Error) IsCode

func (msg *Error) IsCode(code uint64) bool

IsCode judges one error.

func (*Error) JSON

func (msg *Error) JSON() interface{}

JSON creates a properly formatted JSON

func (*Error) MarshalJSON

func (msg *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Error) SetCode

func (msg *Error) SetCode(code uint64) *Error

SetCode sets the error's code

func (*Error) SetMeta

func (msg *Error) SetMeta(data interface{}) *Error

SetMeta sets the error's meta data.

type HTTPContext

type HTTPContext struct {
	Chan         chan struct{}
	DeadLineTime time.Time
}

HTTPContext defined httpContxt

func (*HTTPContext) Deadline

func (ctx *HTTPContext) Deadline() (time.Time, bool)

Deadline defined Deadline time

func (*HTTPContext) Done

func (ctx *HTTPContext) Done() <-chan struct{}

Done defined http done action

func (*HTTPContext) Err

func (ctx *HTTPContext) Err() error

Err defined http action error

func (*HTTPContext) Value

func (ctx *HTTPContext) Value(key interface{}) interface{}

Value nothing

type Hook

type Hook struct {
	OnStart func(context.Context) error
	OnStop  func(context.Context) error
}

A Hook is a pair of start and stop callbacks, either of which can be nil, plus a string identifying the supplier of the hook.

type InjectOption

type InjectOption interface {
	// contains filtered or unexported methods
}

InjectOption defined inject option

func InjectsOption

func InjectsOption(injects ...interface{}) InjectOption

InjectsOption defined Option of Injects

func InjectsValidOption

func InjectsValidOption(injects ...interface{}) InjectOption

InjectsValidOption defined Option of valid

type Injects

type Injects []interface{}

Injects defined some entitys that can be inject to middle , Injects would panic if repetition , Injects can be go base tyle or struct or ptr or interface{}

func (*Injects) Acquire

func (src *Injects) Acquire(ty reflect.Type) interface{}

Acquire defined acquire inject ele from type

func (*Injects) Append

func (src *Injects) Append(target *Injects) *Injects

Append defined array concat

func (*Injects) Get

func (src *Injects) Get(pos int) interface{}

Get defined index of inject

func (*Injects) Has

func (src *Injects) Has(item interface{}) bool

Has defined inject type is existed or not

func (*Injects) Put

func (src *Injects) Put(target interface{}) *Injects

Put defined array Put

func (*Injects) Size

func (src *Injects) Size() int

Size defined inject Size

func (*Injects) Swap

func (src *Injects) Swap(i, j int)

Swap swaps the two values at the specified positions.

func (*Injects) Wire

func (src *Injects) Wire(target interface{}) (err error)

Wire defined wire ele from type

type Lifecycle

type Lifecycle interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Append(h Hook)
}

Lifecycle interface coordinates application lifecycle hooks.

type Option

type Option func(*rush) interface{}

Option defined implement of option

func Empty

func Empty() Option

Empty defined Option of rush

type Plugins

type Plugins []interface{}

Plugins defined those that can be call by reflect , Plugins passby func or a struct that has `Plugin` func

func (*Plugins) Append

func (p *Plugins) Append(target *Plugins) *Plugins

Append defined array concat

func (*Plugins) Get

func (p *Plugins) Get(pos int) interface{}

Get defined index of Plugins

func (*Plugins) Put

func (p *Plugins) Put(target interface{}) *Plugins

Put defined array Put

func (*Plugins) PutHead

func (p *Plugins) PutHead(target interface{}) *Plugins

PutHead defined put ele to head

func (*Plugins) Size

func (p *Plugins) Size() int

Size defined Plugins Size

func (*Plugins) Swap

func (p *Plugins) Swap(i, j int)

Swap swaps the two values at the specified positions.

type PluginsOption

type PluginsOption interface {
	// contains filtered or unexported methods
}

PluginsOption defined plugin option

func MiddlePluginsOption

func MiddlePluginsOption(plugins ...interface{}) PluginsOption

MiddlePluginsOption defined Option of MiddlePlugin

func PluginsValidOption

func PluginsValidOption(plugins ...interface{}) PluginsOption

PluginsValidOption defined Option of valid

func PostPluginsOption

func PostPluginsOption(plugins ...interface{}) PluginsOption

PostPluginsOption defined Option of PostPlugin

func PrePluginsOption

func PrePluginsOption(plugins ...interface{}) PluginsOption

PrePluginsOption defined Option of PrePlugin

type ReverseInject

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

ReverseInject defined a inject , for reverse inject

func (*ReverseInject) Register

func (r *ReverseInject) Register(rFunc interface{})

Register defiend function for Reverse Injects Example: func Route(router *gin.RouterGroup, event events.EventEmmiter, ri *bulrush.ReverseInject) {

ri.Register(RegisterMgo)
ri.Register(RegisterCache)
ri.Register(RegisterSeq)
ri.Register(RegisterMq)
ri.Register(RegisterEvent)
ri.Register(RegisterMock)
ri.Register(RegisterGRPC)
event.Emit("hello", "this is my payload to hello router")

}

Directories

Path Synopsis
benchmarks