yiigo: github.com/iiinsomnia/yiigo Index | Files

package yiigo

import "github.com/iiinsomnia/yiigo"

Package yiigo makes Golang development easier !

Basic usage

MySQL

// default db
yiigo.RegisterDB(yiigo.AsDefault, yiigo.MySQL, "root:root@tcp(localhost:3306)/test")

yiigo.DB.Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)

// other db
yiigo.RegisterDB("foo", yiigo.MySQL, "root:root@tcp(localhost:3306)/foo")

yiigo.UseDB("foo").Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)

MongoDB

// default mongodb
yiigo.RegisterMongoDB(yiigo.AsDefault, "mongodb://localhost:27017")

ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
yiigo.Mongo.Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})

// other mongodb
yiigo.RegisterMongoDB("foo", "mongodb://localhost:27017")

ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
yiigo.UseMongo("foo").Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})

Redis

// default redis
yiigo.RegisterRedis(yiigo.AsDefault, "localhost:6379")

conn, err := yiigo.Redis.Get()

if err != nil {
    log.Fatal(err)
}

defer yiigo.Redis.Put(conn)

conn.Do("SET", "test_key", "hello world")

// other redis
yiigo.RegisterRedis("foo", "localhost:6379")

foo := yiigo.UseRedis("foo")
conn, err := foo.Get()

if err != nil {
    log.Fatal(err)
}

defer foo.Put(conn)

conn.Do("SET", "test_key", "hello world")

Config

// env.toml
//
// [app]
// env = "dev"
// debug = true
// port = 50001

yiigo.UseEnv("env.toml")

yiigo.Env.GetBool("app.debug", true)
yiigo.Env.GetInt("app.port", 12345)
yiigo.Env.GetString("app.env", "dev")

Zipkin

tracer, err := yiigo.NewZipkinTracer("http://localhost:9411/api/v2/spans",
    yiigo.WithZipkinTracerEndpoint("zipkin-test", "localhost"),
    yiigo.WithZipkinTracerSharedSpans(false),
    yiigo.WithZipkinTracerSamplerMod(1),
)

if err != nil {
    log.Fatal(err)
}

client, err := yiigo.NewZipkinClient(tracer)

if err != nil {
    log.Fatal(err)
}

b, err := client.Get(context.Background(), "url...",
    yiigo.WithRequestHeader("Content-Type", "application/json"),
    yiigo.WithRequestTimeout(5*time.Second),
)

if err != nil {
    log.Fatal(err)
}

fmt.Println(string(b))

Logger

// default logger
yiigo.RegisterLogger(yiigo.AsDefault, "app.log")
yiigo.Logger.Info("hello world")

// other logger
yiigo.RegisterLogger("foo", "foo.log")
yiigo.UseLogger("foo").Info("hello world")

For more details, see the documentation for the types and methods.

Index

Package Files

crypto.go db.go doc.go env.go http.go logger.go mailer.go mongo.go redis.go slice.go strings.go utils.go zipkin.go

Constants

const AsDefault = "default"

AsDefault alias for "default"

Variables

var (
    // DB default db connection
    DB *sqlx.DB
)
var Env *env

Env enviroment

var ErrEnvNil = errors.New("yiigo: env config not found")

ErrEnvNil returned when config not found.

var (
    // Logger default logger
    Logger *zap.Logger
)
var (
    // Mongo default mongo client
    Mongo *mongo.Client
)

func AESCBCDecrypt Uses

func AESCBCDecrypt(cipherText, key []byte, iv ...byte) ([]byte, error)

AESCBCDecrypt AES CBC decrypt with PKCS#7 unpadding

func AESCBCEncrypt Uses

func AESCBCEncrypt(plainText, key []byte, iv ...byte) ([]byte, error)

AESCBCEncrypt AES CBC encrypt with PKCS#7 padding

func AddSlashes Uses

func AddSlashes(s string) string

AddSlashes returns a string with backslashes added before characters that need to be escaped.

func Date Uses

func Date(timestamp int64, format ...string) string

Date format a local time/date and returns a string formatted according to the given format string using the given timestamp of int64. The default format is: 2006-01-02 15:04:05.

func Float64sUnique Uses

func Float64sUnique(a []float64) []float64

Float64sUnique takes an input slice of float64s and returns a new slice of float64s without duplicate values.

func HMAC Uses

func HMAC(t, s, key string) string

HMAC Generate a keyed hash value, expects: MD5, SHA1, SHA224, SHA256, SHA384, SHA512.

func HTTPGet Uses

func HTTPGet(url string, options ...HTTPRequestOption) ([]byte, error)

HTTPGet http get request

func HTTPPost Uses

func HTTPPost(url string, body []byte, options ...HTTPRequestOption) ([]byte, error)

HTTPPost http post request

func Hash Uses

func Hash(t, s string) string

Hash Generate a hash value, expects: MD5, SHA1, SHA224, SHA256, SHA384, SHA512.

func IP2Long Uses

func IP2Long(ip string) uint32

IP2Long converts a string containing an (IPv4) Internet Protocol dotted address into a long integer.

func InArray Uses

func InArray(x interface{}, y ...interface{}) bool

InArray checks if x exists in a slice and returns TRUE if x is found.

func InFloat64s Uses

func InFloat64s(x float64, y ...float64) bool

InFloat64s checks if x exists in []float64s and returns TRUE if x is found.

func InInt16s Uses

func InInt16s(x int16, y ...int16) bool

InInt16s checks if x exists in []int16s and returns TRUE if x is found.

func InInt32s Uses

func InInt32s(x int32, y ...int32) bool

InInt32s checks if x exists in []int32s and returns TRUE if x is found.

func InInt64s Uses

func InInt64s(x int64, y ...int64) bool

InInt64s checks if x exists in []int64s and returns TRUE if x is found.

func InInt8s Uses

func InInt8s(x int8, y ...int8) bool

InInt8s checks if x exists in []int8s and returns TRUE if x is found.

func InInts Uses

func InInts(x int, y ...int) bool

InInts checks if x exists in []ints and returns TRUE if x is found.

func InStrings Uses

func InStrings(x string, y ...string) bool

InStrings checks if x exists in []strings and returns TRUE if x is found.

func InUint16s Uses

func InUint16s(x uint16, y ...uint16) bool

InUint16s checks if x exists in []uint16s and returns TRUE if x is found.

func InUint32s Uses

func InUint32s(x uint32, y ...uint32) bool

InUint32s checks if x exists in []uint32s and returns TRUE if x is found.

func InUint64s Uses

func InUint64s(x uint64, y ...uint64) bool

InUint64s checks if x exists in []uint64s and returns TRUE if x is found.

func InUint8s Uses

func InUint8s(x uint8, y ...uint8) bool

InUint8s checks if x exists in []uint8s and returns TRUE if x is found.

func InUints Uses

func InUints(x uint, y ...uint) bool

InUints checks if x exists in []uints and returns TRUE if x is found.

func InsertSQL Uses

func InsertSQL(table string, data interface{}) (string, []interface{})

InsertSQL returns mysql insert sql and binds. param data expects: `struct`, `*struct`, `[]struct`, `[]*struct`, `yiigo.X`, `[]yiigo.X`.

func Int16sUnique Uses

func Int16sUnique(a []int16) []int16

Int16sUnique takes an input slice of int16s and returns a new slice of int16s without duplicate values.

func Int32sUnique Uses

func Int32sUnique(a []int32) []int32

Int32sUnique takes an input slice of int32s and returns a new slice of int32s without duplicate values.

func Int64sUnique Uses

func Int64sUnique(a []int64) []int64

Int64sUnique takes an input slice of int64s and returns a new slice of int64s without duplicate values.

func Int8sUnique Uses

func Int8sUnique(a []int8) []int8

Int8sUnique takes an input slice of int8s and returns a new slice of int8s without duplicate values.

func IntsUnique Uses

func IntsUnique(a []int) []int

IntsUnique takes an input slice of ints and returns a new slice of ints without duplicate values.

func Long2IP Uses

func Long2IP(ip uint32) string

Long2IP converts an long integer address into a string in (IPv4) Internet standard dotted format.

func MD5 Uses

func MD5(s string) string

MD5 calculate the md5 hash of a string.

func MyTimeEncoder Uses

func MyTimeEncoder(t time.Time, e zapcore.PrimitiveArrayEncoder)

MyTimeEncoder zap time encoder.

func NewZipkinTracer Uses

func NewZipkinTracer(reportURL string, options ...ZipkinTracerOption) (*zipkin.Tracer, error)

NewZipkinTracer returns a new zipin tracer

func PGInsertSQL Uses

func PGInsertSQL(table string, data interface{}) (string, []interface{})

PGInsertSQL returns postgres insert sql and binds. param data expects: `struct`, `*struct`, `[]struct`, `[]*struct`, `yiigo.X`, `[]yiigo.X`.

func PGUpdateSQL Uses

func PGUpdateSQL(query string, data interface{}, args ...interface{}) (string, []interface{})

PGUpdateSQL returns postgres update sql and binds. param query expects eg: "UPDATE `table` SET $1 WHERE `id` = $2". param data expects: `struct`, `*struct`, `yiigo.X`.

func PKCS7Padding Uses

func PKCS7Padding(cipherText []byte, blockSize int) []byte

PKCS7Padding PKCS#7 padding

func PKCS7UnPadding Uses

func PKCS7UnPadding(plainText []byte, blockSize int) []byte

PKCS7UnPadding PKCS#7 unpadding

func QuoteMeta Uses

func QuoteMeta(s string) string

QuoteMeta returns a version of str with a backslash character (\) before every character that is among these: . \ + * ? [ ^ ] ( $ )

func RegisterDB Uses

func RegisterDB(name string, driver Driver, dsn string, options ...DBOption) error

RegisterDB register a db, the param `dsn` eg:

MySQL: `username:password@tcp(localhost:3306)/dbname?timeout=10s&charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&loc=Local`;

Postgres: `host=localhost port=5432 user=root password=secret dbname=test connect_timeout=10 sslmode=disable`.

The default `MaxOpenConns` is 20. The default `MaxIdleConns` is 10. The default `ConnMaxLifetime` is 60s.

func RegisterLogger Uses

func RegisterLogger(name, file string, options ...LogOption)

RegisterLogger register logger

func RegisterMailer Uses

func RegisterMailer(name, host string, port int, account, password string)

RegisterMailer register a mailer

func RegisterMongoDB Uses

func RegisterMongoDB(name, dsn string, options ...MongoOption) error

RegisterMongoDB register a mongodb, the param `dsn` eg: `mongodb://username:password@localhost:27017`.

The default `ConnTimeout` is 10s. The default `PoolSize` is 10. The default `MaxConnIdleTime` is 60s.

func RegisterRedis Uses

func RegisterRedis(name, addr string, options ...RedisOption)

RegisterRedis register a redis.

The default `ConnTimeout` is 10s. The default `ReadTimeout` is 10s. The default `WriteTimeout` is 10s. The default `PoolSize` is 10. The default `PoolLimit` is 20. The default `IdleTimeout` is 60s. The default `WaitTimeout` is 10s. The default `PrefillParallelism` is 0.

func SHA1 Uses

func SHA1(s string) string

SHA1 calculate the sha1 hash of a string.

func SearchInt16s Uses

func SearchInt16s(a []int16, x int16) int

SearchInt16s searches for x in a sorted slice of int16s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchInt32s Uses

func SearchInt32s(a []int32, x int32) int

SearchInt32s searches for x in a sorted slice of int32s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchInt64s Uses

func SearchInt64s(a []int64, x int64) int

SearchInt64s searches for x in a sorted slice of int64s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchInt8s Uses

func SearchInt8s(a []int8, x int8) int

SearchInt8s searches for x in a sorted slice of int8s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchUint16s Uses

func SearchUint16s(a []uint16, x uint16) int

SearchUints searches for x in a sorted slice of uint16s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchUint32s Uses

func SearchUint32s(a []uint32, x uint32) int

SearchUint32s searches for x in a sorted slice of uint32s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchUint64s Uses

func SearchUint64s(a []uint64, x uint64) int

SearchUint64s searches for x in a sorted slice of uint64s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchUint8s Uses

func SearchUint8s(a []uint8, x uint8) int

SearchUint8s searches for x in a sorted slice of uint8s and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SearchUints Uses

func SearchUints(a []uint, x uint) int

SearchUints searches for x in a sorted slice of uints and returns the index as specified by Search. The return value is the index to insert x if x is not present (it could be len(a)). The slice must be sorted in ascending order.

func SortInt16s Uses

func SortInt16s(a []int16)

SortInt16s sorts []int16s in increasing order.

func SortInt32s Uses

func SortInt32s(a []int32)

SortInt32s sorts []int32s in increasing order.

func SortInt64s Uses

func SortInt64s(a []int64)

SortInt64s sorts []int64s in increasing order.

func SortInt8s Uses

func SortInt8s(a []int8)

SortInt8s sorts []int8s in increasing order.

func SortUint16s Uses

func SortUint16s(a []uint16)

SortUint16s sorts []uint16s in increasing order.

func SortUint32s Uses

func SortUint32s(a []uint32)

SortUint32s sorts []uint32s in increasing order.

func SortUint64s Uses

func SortUint64s(a []uint64)

SortUint64s sorts []uint64s in increasing order.

func SortUint8s Uses

func SortUint8s(a []uint8)

SortUint8s sorts []uint8s in increasing order.

func SortUints Uses

func SortUints(a []uint)

SortUints sorts []uints in increasing order.

func StartWithZipkin Uses

func StartWithZipkin(t *zipkin.Tracer, req *http.Request) zipkin.Span

StartWithZipkin returns a new zipkin span

func StringsUnique Uses

func StringsUnique(a []string) []string

StringsUnique takes an input slice of strings and returns a new slice of strings without duplicate values.

func StripSlashes Uses

func StripSlashes(s string) string

StripSlashes returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\).

func Uint16sUnique Uses

func Uint16sUnique(a []uint16) []uint16

Uint16sUnique takes an input slice of uint16s and returns a new slice of uint16s without duplicate values.

func Uint32sUnique Uses

func Uint32sUnique(a []uint32) []uint32

Uint32sUnique takes an input slice of uint32s and returns a new slice of uint32s without duplicate values.

func Uint64sUnique Uses

func Uint64sUnique(a []uint64) []uint64

Uint64sUnique takes an input slice of uint64s and returns a new slice of uint64s without duplicate values.

func Uint8sUnique Uses

func Uint8sUnique(a []uint8) []uint8

Uint8sUnique takes an input slice of uint8s and returns a new slice of uint8s without duplicate values.

func UintsUnique Uses

func UintsUnique(a []uint) []uint

UintsUnique takes an input slice of uints and returns a new slice of uints without duplicate values.

func UpdateSQL Uses

func UpdateSQL(query string, data interface{}, args ...interface{}) (string, []interface{})

UpdateSQL returns mysql update sql and binds. param query expects eg: "UPDATE `table` SET ? WHERE `id` = ?". param data expects: `struct`, `*struct`, `yiigo.X`.

func UseDB Uses

func UseDB(name ...string) *sqlx.DB

UseDB returns a db.

func UseEnv Uses

func UseEnv(file string) error

UseEnv use `toml` config file.

func UseLogger Uses

func UseLogger(name string) *zap.Logger

UseLogger returns a logger

func UseMongo Uses

func UseMongo(name ...string) *mongo.Client

UseMongo returns a mongo client.

type CDATA Uses

type CDATA string

CDATA XML CDATA section which is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup.

func (CDATA) MarshalXML Uses

func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML encodes the receiver as zero or more XML elements.

type Concern Uses

type Concern int

Concern for replica sets and replica set shards determines which data to return from a query.

const (
    Local        Concern = 1 // the query should return the instance’s most recent data.
    Available    Concern = 2 // the query should return data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
    Majority     Concern = 3 // the query should return the instance’s most recent data acknowledged as having been written to a majority of members in the replica set.
    Linearizable Concern = 4 // that the query should return data that reflects all successful writes issued with a write concern of "majority" and acknowledged prior to the start of the read operation.
    Snapshot     Concern = 5 // only available for operations within multi-document transactions.
)

type DBOption Uses

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

DBOption configures how we set up the db

func WithDBConnMaxLifetime Uses

func WithDBConnMaxLifetime(d time.Duration) DBOption

WithDBConnMaxLifetime specifies the `ConnMaxLifetime` to db. ConnMaxLifetime sets the maximum amount of time a connection may be reused.

Expired connections may be closed lazily before reuse.

If d <= 0, connections are reused forever.

func WithDBMaxIdleConns Uses

func WithDBMaxIdleConns(n int) DBOption

WithDBMaxIdleConns specifies the `MaxIdleConns` to db. MaxIdleConns sets the maximum number of connections in the idle connection pool.

If MaxOpenConns is greater than 0 but less than the new MaxIdleConns, then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.

If n <= 0, no idle connections are retained.

The default max idle connections is currently 2. This may change in a future release.

func WithDBMaxOpenConns Uses

func WithDBMaxOpenConns(n int) DBOption

WithDBMaxOpenConns specifies the `MaxOpenConns` to db. MaxOpenConns sets the maximum number of open connections to the database.

If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit.

If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).

type Driver Uses

type Driver int

Driver indicates the db drivers.

const (
    MySQL    Driver = 1
    Postgres Driver = 2
)

type EMail Uses

type EMail struct {
    Title   string
    Subject string
    From    string
    To      []string
    Cc      []string
    Content string
    Attach  []string
}

EMail email

type EMailDialer Uses

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

EMailDialer email dialer

var (
    Mailer *EMailDialer
)

func UseMailer Uses

func UseMailer(name string) *EMailDialer

UseMailer returns a mailer

func (*EMailDialer) Send Uses

func (m *EMailDialer) Send(e *EMail, options ...EMailOption) error

Send send an email.

type EMailOption Uses

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

EMailOption configures how we set up the email

func WithEMailCharset Uses

func WithEMailCharset(s string) EMailOption

WithEMailCharset specifies the `Charset` to email.

func WithEMailContentType Uses

func WithEMailContentType(s string) EMailOption

WithEMailContentType specifies the `ContentType` to email.

func WithEMailEncoding Uses

func WithEMailEncoding(e gomail.Encoding) EMailOption

WithEMailEncoding specifies the `Encoding` to email.

type HTTPClient Uses

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

HTTPClient http client

func NewHTTPClient Uses

func NewHTTPClient(options ...HTTPClientOption) *HTTPClient

NewHTTPClient returns a new http client

func (*HTTPClient) Get Uses

func (h *HTTPClient) Get(url string, options ...HTTPRequestOption) ([]byte, error)

Get http get request

func (*HTTPClient) Post Uses

func (h *HTTPClient) Post(url string, body []byte, options ...HTTPRequestOption) ([]byte, error)

Post http post request

type HTTPClientOption Uses

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

HTTPClientOption configures how we set up the http client

func WithHTTPDefaultTimeout Uses

func WithHTTPDefaultTimeout(d time.Duration) HTTPClientOption

WithHTTPDefaultTimeout specifies the `DefaultTimeout` to http client.

func WithHTTPDialFallbackDelay Uses

func WithHTTPDialFallbackDelay(d time.Duration) HTTPClientOption

WithHTTPDialFallbackDelay specifies the `FallbackDelay` to net.Dialer.

func WithHTTPDialKeepAlive Uses

func WithHTTPDialKeepAlive(d time.Duration) HTTPClientOption

WithHTTPDialKeepAlive specifies the `KeepAlive` to net.Dialer.

func WithHTTPDialTimeout Uses

func WithHTTPDialTimeout(d time.Duration) HTTPClientOption

WithHTTPDialTimeout specifies the `DialTimeout` to net.Dialer.

func WithHTTPExpectContinueTimeout Uses

func WithHTTPExpectContinueTimeout(d time.Duration) HTTPClientOption

WithHTTPExpectContinueTimeout specifies the `ExpectContinueTimeout` to http client.

func WithHTTPIdleConnTimeout Uses

func WithHTTPIdleConnTimeout(d time.Duration) HTTPClientOption

WithHTTPIdleConnTimeout specifies the `IdleConnTimeout` to http client.

func WithHTTPMaxConnsPerHost Uses

func WithHTTPMaxConnsPerHost(n int) HTTPClientOption

WithHTTPMaxConnsPerHost specifies the `MaxConnsPerHost` to http client.

func WithHTTPMaxIdleConns Uses

func WithHTTPMaxIdleConns(n int) HTTPClientOption

WithHTTPMaxIdleConns specifies the `MaxIdleConns` to http client.

func WithHTTPMaxIdleConnsPerHost Uses

func WithHTTPMaxIdleConnsPerHost(n int) HTTPClientOption

WithHTTPMaxIdleConnsPerHost specifies the `MaxIdleConnsPerHost` to http client.

func WithHTTPTLSConfig Uses

func WithHTTPTLSConfig(c *tls.Config) HTTPClientOption

WithHTTPTLSConfig specifies the `TLSClientConfig` to http client.

func WithHTTPTLSHandshakeTimeout Uses

func WithHTTPTLSHandshakeTimeout(d time.Duration) HTTPClientOption

WithHTTPTLSHandshakeTimeout specifies the `TLSHandshakeTimeout` to http client.

type HTTPRequestOption Uses

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

HTTPRequestOption configures how we set up the http request

func WithRequestClose Uses

func WithRequestClose(b bool) HTTPRequestOption

WithRequestClose specifies close the connection after replying to this request (for servers) or after sending this request and reading its response (for clients).

func WithRequestCookies Uses

func WithRequestCookies(cookies ...*http.Cookie) HTTPRequestOption

WithRequestCookies specifies the cookies to http request.

func WithRequestHeader Uses

func WithRequestHeader(key, value string) HTTPRequestOption

WithRequestHeader specifies the header to http request.

func WithRequestTimeout Uses

func WithRequestTimeout(d time.Duration) HTTPRequestOption

WithRequestTimeout specifies the timeout to http request.

func WithZipkinSpanTag Uses

func WithZipkinSpanTag(key, value string) HTTPRequestOption

WithZipkinSpanTag specifies the zipkin span tag to zipkin http request.

type Int16Slice Uses

type Int16Slice []int16

Int16Slice attaches the methods of Interface to []int16, sorting a increasing order.

func (Int16Slice) Len Uses

func (p Int16Slice) Len() int

func (Int16Slice) Less Uses

func (p Int16Slice) Less(i, j int) bool

func (Int16Slice) Swap Uses

func (p Int16Slice) Swap(i, j int)

type Int32Slice Uses

type Int32Slice []int32

Int32Slice attaches the methods of Interface to []int32, sorting a increasing order.

func (Int32Slice) Len Uses

func (p Int32Slice) Len() int

func (Int32Slice) Less Uses

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Swap Uses

func (p Int32Slice) Swap(i, j int)

type Int64Slice Uses

type Int64Slice []int64

Int64Slice attaches the methods of Interface to []int64, sorting a increasing order.

func (Int64Slice) Len Uses

func (p Int64Slice) Len() int

func (Int64Slice) Less Uses

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap Uses

func (p Int64Slice) Swap(i, j int)

type Int8Slice Uses

type Int8Slice []int8

Int8Slice attaches the methods of Interface to []int8, sorting a increasing order.

func (Int8Slice) Len Uses

func (p Int8Slice) Len() int

func (Int8Slice) Less Uses

func (p Int8Slice) Less(i, j int) bool

func (Int8Slice) Swap Uses

func (p Int8Slice) Swap(i, j int)

type LogOption Uses

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

LogOption configures how we set up the logger

func WithLogCompress Uses

func WithLogCompress(b bool) LogOption

WithLogCompress specifies the `Compress` to logger. Compress determines if the rotated log files should be compressed using gzip.

func WithLogDebug Uses

func WithLogDebug(b bool) LogOption

WithLogDebug specifies the `Debug` mode to logger.

func WithLogMaxAge Uses

func WithLogMaxAge(n int) LogOption

WithLogMaxAge specifies the `MaxAge` to logger. MaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. Note that a day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc. The default is not to remove old log files based on age.

func WithLogMaxBackups Uses

func WithLogMaxBackups(n int) LogOption

WithLogMaxBackups specifies the `MaxBackups` to logger. MaxBackups is the maximum number of old log files to retain. The default is to retain all old log files (though MaxAge may still cause them to get deleted.)

func WithLogMaxSize Uses

func WithLogMaxSize(n int) LogOption

WithLogMaxSize specifies the `MaxSize` to logger. MaxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 100 megabytes.

type Mode Uses

type Mode int

Mode indicates the user's preference on reads.

const (
    Primary            Mode = 1 // Default mode. All operations read from the current replica set primary.
    PrimaryPreferred   Mode = 2 // Read from the primary if available. Read from the secondary otherwise.
    Secondary          Mode = 3 // Read from one of the nearest secondary members of the replica set.
    SecondaryPreferred Mode = 4 // Read from one of the nearest secondaries if available. Read from primary otherwise.
    Nearest            Mode = 5 // Read from one of the nearest members, irrespective of it being primary or secondary.
)

type MongoOption Uses

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

MongoOption configures how we set up the mongo

func WithMongoAppName Uses

func WithMongoAppName(s string) MongoOption

WithMongoAppName specifies the `AppName` to mongo. AppName sets the client application name. This value is used by MongoDB when it logs connection information and profile information, such as slow queries.

func WithMongoCompressors Uses

func WithMongoCompressors(s ...string) MongoOption

WithMongoCompressors specifies the `Compressors` to mongo. Compressors sets the compressors that can be used when communicating with a server.

func WithMongoConnTimeout Uses

func WithMongoConnTimeout(d time.Duration) MongoOption

WithMongoConnTimeout specifies the `ConnTimeout` to mongo. ConnectTimeout sets the timeout for an initial connection to a server.

func WithMongoDirect Uses

func WithMongoDirect(b bool) MongoOption

WithMongoDirect specifies the `Direct` to mongo. Direct sets whether the driver should connect directly to the server instead of auto-discovering other servers in the cluster.

func WithMongoHeartbeatInterval Uses

func WithMongoHeartbeatInterval(d time.Duration) MongoOption

WithMongoHeartbeatInterval specifies the `HeartbeatInterval` to mongo. HeartbeatInterval sets the interval to wait between server monitoring checks.

func WithMongoHosts Uses

func WithMongoHosts(s ...string) MongoOption

WithMongoHosts specifies the `Hosts` to mongo. Hosts sets the initial list of addresses from which to discover the rest of the cluster.

func WithMongoLocalThreshold Uses

func WithMongoLocalThreshold(d time.Duration) MongoOption

WithMongoLocalThreshold specifies the `LocalThreshold` to mongo. LocalThreshold sets how far to distribute queries, beyond the server with the fastest round-trip time. If a server's roundtrip time is more than LocalThreshold slower than the the fastest, the driver will not send queries to that server.

func WithMongoMaxConnIdleTime Uses

func WithMongoMaxConnIdleTime(d time.Duration) MongoOption

WithMongoMaxConnIdleTime specifies the `MaxConnIdleTime` to mongo. MaxConnIdleTime sets the maximum number of milliseconds that a connection can remain idle in a connection pool before being removed and closed.

func WithMongoMode Uses

func WithMongoMode(m Mode) MongoOption

WithMongoMode specifies the `Mode` to mongo. Mode sets the read preference.

func WithMongoPoolSize Uses

func WithMongoPoolSize(n int) MongoOption

WithMongoPoolSize specifies the `PoolSize` to mongo. MaxPoolSize sets the max size of a server's connection pool.

func WithMongoReadConcern Uses

func WithMongoReadConcern(c Concern) MongoOption

WithMongoReadConcern specifies the `ReadConcern` to mongo. ReadConcern sets the read concern.

func WithMongoReplicaSet Uses

func WithMongoReplicaSet(s string) MongoOption

WithMongoReplicaSet specifies the `ReplicaSet` to mongo. ReplicaSet sets the name of the replica set of the cluster.

func WithMongoRetryWrites Uses

func WithMongoRetryWrites(b bool) MongoOption

WithMongoRetryWrites specifies the `RetryWrites` to mongo. RetryWrites sets whether the client has retryable writes enabled.

func WithMongoServerSelectionTimeout Uses

func WithMongoServerSelectionTimeout(d time.Duration) MongoOption

WithMongoServerSelectionTimeout specifies the `ServerSelectionTimeout` to mongo. ServerSelectionTimeout sets a timeout in milliseconds to block for server selection.

func WithMongoSocketTimeout Uses

func WithMongoSocketTimeout(d time.Duration) MongoOption

WithMongoSocketTimeout specifies the `SocketTimeout` to mongo. SocketTimeout sets the time in milliseconds to attempt to send or receive on a socket before the attempt times out.

func WithMongoTLSConfig Uses

func WithMongoTLSConfig(c *tls.Config) MongoOption

WithMongoTLSConfig specifies the `TLSConfig` to mongo. SetTLSConfig sets the tls.Config.

func WithMongoWriteConcern Uses

func WithMongoWriteConcern(c ...writeconcern.Option) MongoOption

WithMongoWriteConcern specifies the `WriteConcern` to mongo. WriteConcern sets the write concern.

func WithMongoZlibLevel Uses

func WithMongoZlibLevel(l int) MongoOption

WithMongoZlibLevel specifies the `ZlibLevel` to mongo. ZlibLevel sets the level for the zlib compressor.

type RedisConn Uses

type RedisConn struct {
    redis.Conn
}

RedisConn redis connection resource

func (RedisConn) Close Uses

func (r RedisConn) Close()

Close close connection resorce

type RedisOption Uses

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

RedisOption configures how we set up the db

func WithRedisConnTimeout Uses

func WithRedisConnTimeout(d time.Duration) RedisOption

WithRedisConnTimeout specifies the `ConnTimeout` to redis.

func WithRedisDatabase Uses

func WithRedisDatabase(n int) RedisOption

WithRedisDatabase specifies the `Database` to redis.

func WithRedisIdleTimeout Uses

func WithRedisIdleTimeout(d time.Duration) RedisOption

WithRedisIdleTimeout specifies the `IdleTimeout` to redis.

func WithRedisPassword Uses

func WithRedisPassword(s string) RedisOption

WithRedisPassword specifies the `Password` to redis.

func WithRedisPoolLimit Uses

func WithRedisPoolLimit(n int) RedisOption

WithRedisPoolLimit specifies the `PoolLimit` to redis.

func WithRedisPoolSize Uses

func WithRedisPoolSize(n int) RedisOption

WithRedisPoolSize specifies the `PoolSize` to redis.

func WithRedisPrefillParallelism Uses

func WithRedisPrefillParallelism(n int) RedisOption

WithRedisPrefillParallelism specifies the `PrefillParallelism` to redis. A non-zero value of prefillParallelism causes the pool to be pre-filled.

func WithRedisReadTimeout Uses

func WithRedisReadTimeout(d time.Duration) RedisOption

WithRedisReadTimeout specifies the `ReadTimeout` to redis.

func WithRedisWaitTimeout Uses

func WithRedisWaitTimeout(d time.Duration) RedisOption

WithRedisWaitTimeout specifies the `WaitTimeout` to redis. A timeout of 0 means an indefinite wait.

func WithRedisWriteTimeout Uses

func WithRedisWriteTimeout(d time.Duration) RedisOption

WithRedisWriteTimeout specifies the `WriteTimeout` to redis.

type RedisPoolResource Uses

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

RedisPoolResource redis pool resource

var (
    // Redis default redis connection pool
    Redis *RedisPoolResource
)

func UseRedis Uses

func UseRedis(name ...string) *RedisPoolResource

UseRedis returns a redis pool.

func (*RedisPoolResource) Get Uses

func (r *RedisPoolResource) Get() (RedisConn, error)

Get get a connection resource from the pool.

func (*RedisPoolResource) Put Uses

func (r *RedisPoolResource) Put(rc RedisConn)

Put returns a connection resource to the pool.

type Uint16Slice Uses

type Uint16Slice []uint16

Uint16Slice attaches the methods of Interface to []uint16, sorting a increasing order.

func (Uint16Slice) Len Uses

func (p Uint16Slice) Len() int

func (Uint16Slice) Less Uses

func (p Uint16Slice) Less(i, j int) bool

func (Uint16Slice) Swap Uses

func (p Uint16Slice) Swap(i, j int)

type Uint32Slice Uses

type Uint32Slice []uint32

Uint32Slice attaches the methods of Interface to []uint, sorting a increasing order.

func (Uint32Slice) Len Uses

func (p Uint32Slice) Len() int

func (Uint32Slice) Less Uses

func (p Uint32Slice) Less(i, j int) bool

func (Uint32Slice) Swap Uses

func (p Uint32Slice) Swap(i, j int)

type Uint64Slice Uses

type Uint64Slice []uint64

Uint64Slice attaches the methods of Interface to []uint64, sorting a increasing order.

func (Uint64Slice) Len Uses

func (p Uint64Slice) Len() int

func (Uint64Slice) Less Uses

func (p Uint64Slice) Less(i, j int) bool

func (Uint64Slice) Swap Uses

func (p Uint64Slice) Swap(i, j int)

type Uint8Slice Uses

type Uint8Slice []uint8

Uint8Slice attaches the methods of Interface to []uint8, sorting a increasing order.

func (Uint8Slice) Len Uses

func (p Uint8Slice) Len() int

func (Uint8Slice) Less Uses

func (p Uint8Slice) Less(i, j int) bool

func (Uint8Slice) Swap Uses

func (p Uint8Slice) Swap(i, j int)

type UintSlice Uses

type UintSlice []uint

UintSlice attaches the methods of Interface to []uint, sorting a increasing order.

func (UintSlice) Len Uses

func (p UintSlice) Len() int

func (UintSlice) Less Uses

func (p UintSlice) Less(i, j int) bool

func (UintSlice) Swap Uses

func (p UintSlice) Swap(i, j int)

type X Uses

type X map[string]interface{}

X is a convenient alias for a map[string]interface{}.

type ZipkinClient Uses

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

ZipkinClient zipkin client

func NewZipkinClient Uses

func NewZipkinClient(t *zipkin.Tracer, options ...ZipkinClientOption) (*ZipkinClient, error)

NewZipkinClient returns a new zipin client

func (*ZipkinClient) Get Uses

func (z *ZipkinClient) Get(ctx context.Context, url string, options ...HTTPRequestOption) ([]byte, error)

Get zipkin get request

func (*ZipkinClient) Post Uses

func (z *ZipkinClient) Post(ctx context.Context, url string, body []byte, options ...HTTPRequestOption) ([]byte, error)

Post zipkin post request

type ZipkinClientOption Uses

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

ZipkinClientOption configures how we set up the zipkin client

func WithZipkinClientTag Uses

func WithZipkinClientTag(key, value string) ZipkinClientOption

WithZipkinClientTag specifies the `Tags` to zipkin client.

func WithZipkinClientTrace Uses

func WithZipkinClientTrace(b bool) ZipkinClientOption

WithZipkinClientTrace specifies the `HttpTrace` to zipkin client.

func WithZipkinHTTPClient Uses

func WithZipkinHTTPClient(options ...HTTPClientOption) ZipkinClientOption

WithZipkinHTTPClient specifies the `Client` to zipkin client.

func WithZipkinRoundTripper Uses

func WithZipkinRoundTripper(rt http.RoundTripper) ZipkinClientOption

WithZipkinRoundTripper specifies the `RoundTripper` to zipkin transport.

func WithZipkinTransportErrHandler Uses

func WithZipkinTransportErrHandler(fn zipkinHTTP.ErrHandler) ZipkinClientOption

WithZipkinTransportErrHandler specifies the `ErrHandler` to zipkin transport.

func WithZipkinTransportErrResponseReader Uses

func WithZipkinTransportErrResponseReader(fn zipkinHTTP.ErrResponseReader) ZipkinClientOption

WithZipkinTransportErrResponseReader specifies the `ErrResponseReader` to zipkin transport.

func WithZipkinTransportLogger Uses

func WithZipkinTransportLogger(l *log.Logger) ZipkinClientOption

WithZipkinTransportLogger specifies the `Logger` to zipkin transport.

func WithZipkinTransportRequestSampler Uses

func WithZipkinTransportRequestSampler(fn zipkinHTTP.RequestSamplerFunc) ZipkinClientOption

WithZipkinTransportRequestSampler specifies the `RequestSampler` to zipkin transport.

func WithZipkinTransportTag Uses

func WithZipkinTransportTag(key, value string) ZipkinClientOption

WithZipkinTransportTag specifies the `Tags` to zipkin transport.

func WithZipkinTransportTrace Uses

func WithZipkinTransportTrace(b bool) ZipkinClientOption

WithZipkinTransportTrace specifies the `HttpTrace` to zipkin transport.

type ZipkinTracerOption Uses

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

ZipkinTracerOption configures how we set up the zipkin tracer

func WithZipkinReporterBatchInterval Uses

func WithZipkinReporterBatchInterval(t time.Duration) ZipkinTracerOption

WithZipkinReporterBatchInterval specifies the `BatchInterval` to zipkin reporter.

func WithZipkinReporterBatchSize Uses

func WithZipkinReporterBatchSize(i int) ZipkinTracerOption

WithZipkinReporterBatchSize specifies the `BatchSize` to zipkin reporter.

func WithZipkinReporterClient Uses

func WithZipkinReporterClient(options ...HTTPClientOption) ZipkinTracerOption

WithZipkinReporterClient specifies the `Client` to zipkin reporter.

func WithZipkinReporterLogger Uses

func WithZipkinReporterLogger(l *log.Logger) ZipkinTracerOption

WithZipkinReporterLogger specifies the `Logger` to zipkin reporter.

func WithZipkinReporterMaxBacklog Uses

func WithZipkinReporterMaxBacklog(i int) ZipkinTracerOption

WithZipkinReporterMaxBacklog specifies the `MaxBacklog` to zipkin reporter.

func WithZipkinReporterRequestCallback Uses

func WithZipkinReporterRequestCallback(fn zipkinHTTPReporter.RequestCallbackFn) ZipkinTracerOption

WithZipkinReporterRequestCallback specifies the `RequestCallback` to zipkin reporter.

func WithZipkinReporterSerializer Uses

func WithZipkinReporterSerializer(s reporter.SpanSerializer) ZipkinTracerOption

WithZipkinReporterSerializer specifies the `Serializer` to zipkin reporter.

func WithZipkinTracerEndpoint Uses

func WithZipkinTracerEndpoint(name, host string) ZipkinTracerOption

WithZipkinTracerEndpoint specifies the `Endpoint` to zipkin tracer.

func WithZipkinTracerExtractFailurePolicy Uses

func WithZipkinTracerExtractFailurePolicy(p zipkin.ExtractFailurePolicy) ZipkinTracerOption

WithZipkinTracerExtractFailurePolicy specifies the `ExtractFailurePolicy` to zipkin tracer.

func WithZipkinTracerIDGenerator Uses

func WithZipkinTracerIDGenerator(g idgenerator.IDGenerator) ZipkinTracerOption

WithZipkinTracerIDGenerator specifies the `IDGenerator` to zipkin tracer.

func WithZipkinTracerNoop Uses

func WithZipkinTracerNoop(b bool) ZipkinTracerOption

WithZipkinTracerNoop specifies the `Noop` to zipkin tracer.

func WithZipkinTracerSamplerMod Uses

func WithZipkinTracerSamplerMod(m int) ZipkinTracerOption

WithZipkinTracerSamplerMod specifies the `Sampler` to zipkin tracer.

func WithZipkinTracerSharedSpans Uses

func WithZipkinTracerSharedSpans(b bool) ZipkinTracerOption

WithZipkinTracerSharedSpans specifies the `SharedSpans` to zipkin tracer.

func WithZipkinTracerTag Uses

func WithZipkinTracerTag(key, value string) ZipkinTracerOption

WithZipkinTracerTag specifies the `Tags` to zipkin tracer.

func WithZipkinTracerUnsampledNoop Uses

func WithZipkinTracerUnsampledNoop(b bool) ZipkinTracerOption

WithZipkinTracerUnsampledNoop specifies the `UnsampledNoop` to zipkin tracer.

Package yiigo imports 50 packages (graph). Updated 2019-09-12. Refresh now. Tools for package owners.