boot

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 13 Imported by: 0

README

boot

GoDoc

This package is used to boot dependencies, e.g. open database connections. It also provides a dependency injection container.

Benchmark for di bind and get ran on a MacBook Pro 2.9 GHz Intel Core i5, 8GB 1867 MHz DDR3:

go test -bench=.

goos: darwin
goarch: amd64
pkg: github.com/dakalab/golib/boot
BenchmarkDI-4   	50000000	        34.8 ns/op	       0 B/op	       0 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableMock

func DisableMock()

DisableMock disables mocking, restore default functions

func EnableMock

func EnableMock() (*sql.DB, sqlmock.Sqlmock)

EnableMock enables mocking

func InitTracing

func InitTracing(cfg *config.TracingConfig) io.Closer

InitTracing initializes global tracer

func MockFailOpenDB added in v0.3.1

func MockFailOpenDB()

MockFailOpenDB mocks open db failure

func OpenDB

func OpenDB(config *config.DatabaseConfig) (*sql.DB, error)

OpenDB opens a DB connection

func OpenGRPC added in v0.2.0

func OpenGRPC(cfg *config.ClientConfig) *grpc.ClientConn

OpenGRPC opens gRPC connection

func SetGlobalDI

func SetGlobalDI(di DependencyInjecter)

SetGlobalDI sets the global DI

Types

type Container

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

Container is the structure representing the dependency injecter

func DI

func DI() *Container

DI returns a new instance of Container

func (*Container) Bind

func (di *Container) Bind(k interface{}, v interface{}) DependencyInjecter

Bind binds a value to a key

func (*Container) Get

func (di *Container) Get(key interface{}) interface{}

Get gets the value bound to the key or nil if no value is present.

func (*Container) Unbind

func (di *Container) Unbind(k interface{}) DependencyInjecter

Unbind unbinds a value from a key

type DependencyInjecter added in v0.1.1

type DependencyInjecter interface {
	Bind(k interface{}, v interface{}) DependencyInjecter
	Unbind(k interface{}) DependencyInjecter
	Get(key interface{}) interface{}
}

DependencyInjecter is the interface of dependency injecter

func GlobalDI

func GlobalDI() DependencyInjecter

GlobalDI returns the global DI

func MustGetGlobalDI

func MustGetGlobalDI() DependencyInjecter

MustGetGlobalDI returns the global DI, panic when it is nil

type RedisClient

type RedisClient interface {
	redis.UniversalClient
}

RedisClient is the redis client wrapper

func OpenRedis

func OpenRedis(config *config.RedisConfig) RedisClient

OpenRedis connects to redis server and get a redis client.

Please note that IdleTimeout option should be smaller than timeout, refer: https://github.com/go-redis/redis/issues/84

Jump to

Keyboard shortcuts

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