yiigo

package module
v4.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 59 Imported by: 7

README

Documentation

Overview

Package yiigo makes Golang development easier !

Basic usage

MySQL

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

// other db
yiigo.DB("foo").Get(&User{}, "SELECT * FROM `user` WHERE `id` = ?", 1)
yiigo.Orm("foo").First(&User{}, 1)

MongoDB

// default mongodb
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

defer cancel()

yiigo.Mongo().Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})

// other mongodb
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

defer cancel()

yiigo.Mongo("foo").Database("test").Collection("numbers").InsertOne(ctx, bson.M{"name": "pi", "value": 3.14159})

Redis

// default redis
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
conn, err := yiigo.Redis("foo").Get()

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

defer yiigo.Redis("foo").Put(conn)

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

Config

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

yiigo.Env("app.env").String("dev")
yiigo.Env("app.debug").Bool(true)
yiigo.Env("app.port").Int(8000)

Zipkin

reporter := yiigo.NewZipkinHTTPReporter("http://localhost:9411/api/v2/spans")

// sampler
sampler := zipkin.NewModuloSampler(1)
// endpoint
endpoint, _ := zipkin.NewEndpoint("yiigo-zipkin", "localhost")

tracer, err := yiigo.NewZipkinTracer(reporter,
    zipkin.WithLocalEndpoint(endpoint),
    zipkin.WithSharedSpans(false),
    zipkin.WithSampler(sampler),
)

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

client, err := tracer.HTTPClient(yiigo.WithZipkinClientOptions(zipkinHttp.ClientTrace(true)))

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.Logger().Info("hello world")

// other logger
yiigo.Logger("foo").Info("hello world")

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

Index

Constants

View Source
const (
	MySQL    = "mysql"
	Postgres = "postgres"
)
View Source
const (
	Primary            = "primary"             // Default mode. All operations read from the current replica set primary.
	PrimaryPreferred   = "primary_preferred"   // Read from the primary if available. Read from the secondary otherwise.
	Secondary          = "secondary"           // Read from one of the nearest secondary members of the replica set.
	SecondaryPreferred = "secondary_preferred" // Read from one of the nearest secondaries if available. Read from primary otherwise.
	Nearest            = "nearest"             // Read from one of the nearest members, irrespective of it being primary or secondary.
)
View Source
const AsDefault = "default"

AsDefault alias for "default"

Variables

View Source
var BufPool = NewBufferPool(4 << 10) // 4KB

BufPool buffer pool

View Source
var ErrConfigNil = errors.New("yiigo: config not found")

ErrConfigNil returned when config not found.

Functions

func AESCBCDecrypt

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

AESCBCDecrypt AES CBC decrypt with PKCS#7 unpadding

func AESCBCEncrypt

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

AESCBCEncrypt AES CBC encrypt with PKCS#7 padding

func AddSlashes

func AddSlashes(s string) string

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

func DB

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

DB returns a db.

func Date

func Date(timestamp int64, layout ...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 layout is: 2006-01-02 15:04:05.

func Float64sUnique

func Float64sUnique(a []float64) []float64

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

func GenerateRSAKey added in v4.1.1

func GenerateRSAKey(bits int) (privateKey, publicKey []byte, err error)

GenerateRSAKey returns rsa private and public key

func HMAC

func HMAC(algo HashAlgo, s, key string) string

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

func HTTPGet

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

HTTPGet http get request

func HTTPPost

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

HTTPPost http post request

func Hash

func Hash(algo HashAlgo, s string) string

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

func IP2Long

func IP2Long(ip string) uint32

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

func InArray

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

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

func InFloat64s

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

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

func InInt16s

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

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

func InInt32s

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

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

func InInt64s

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

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

func InInt8s

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

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

func InInts

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

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

func InStrings

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

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

func InUint16s

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

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

func InUint32s

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

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

func InUint64s

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

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

func InUint8s

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

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

func InUints

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

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

func InsertSQL

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

func Int16sUnique(a []int16) []int16

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

func Int32sUnique

func Int32sUnique(a []int32) []int32

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

func Int64sUnique

func Int64sUnique(a []int64) []int64

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

func Int8sUnique

func Int8sUnique(a []int8) []int8

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

func IntsUnique

func IntsUnique(a []int) []int

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

func Logger

func Logger(name ...string) *zap.Logger

Logger returns a logger

func Long2IP

func Long2IP(ip uint32) string

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

func MD5

func MD5(s string) string

MD5 calculate the md5 hash of a string.

func Mongo

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

Mongo returns a mongo client.

func MyTimeEncoder

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

MyTimeEncoder zap time encoder.

func NewZipkinHTTPReporter

func NewZipkinHTTPReporter(url string, options ...ZipkinReporterOption) reporter.Reporter

NewZipkinHTTPReporter returns a new zipin http reporter

func Orm

func Orm(name ...string) *gorm.DB

Orm returns an orm's db.

func PGInsertSQL

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

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

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

PKCS7Padding PKCS#7 padding

func PKCS7UnPadding

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

PKCS7UnPadding PKCS#7 unpadding

func QuoteMeta

func QuoteMeta(s string) string

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

func RSADecrypt added in v4.1.1

func RSADecrypt(cipherText, privateKey []byte) ([]byte, error)

RSADecrypt rsa decrypt with private key

func RSAEncrypt added in v4.1.1

func RSAEncrypt(data, publicKey []byte) ([]byte, error)

RSAEncrypt rsa encrypt with public key

func RSASignWithSha256 added in v4.1.1

func RSASignWithSha256(data, privateKey []byte) ([]byte, error)

RSASignWithSha256 returns rsa signature with sha256

func RSAVerifyWithSha256 added in v4.1.1

func RSAVerifyWithSha256(data, signature, publicKey []byte) error

RSAVerifyWithSha256 verifies rsa signature with sha256

func SHA1

func SHA1(s string) string

SHA1 calculate the sha1 hash of a string.

func SearchInt16s

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

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

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

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

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

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

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

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

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

func SortInt16s(a []int16)

SortInt16s sorts []int16s in increasing order.

func SortInt32s

func SortInt32s(a []int32)

SortInt32s sorts []int32s in increasing order.

func SortInt64s

func SortInt64s(a []int64)

SortInt64s sorts []int64s in increasing order.

func SortInt8s

func SortInt8s(a []int8)

SortInt8s sorts []int8s in increasing order.

func SortUint16s

func SortUint16s(a []uint16)

SortUint16s sorts []uint16s in increasing order.

func SortUint32s

func SortUint32s(a []uint32)

SortUint32s sorts []uint32s in increasing order.

func SortUint64s

func SortUint64s(a []uint64)

SortUint64s sorts []uint64s in increasing order.

func SortUint8s

func SortUint8s(a []uint8)

SortUint8s sorts []uint8s in increasing order.

func SortUints

func SortUints(a []uint)

SortUints sorts []uints in increasing order.

func StrToTime added in v4.1.2

func StrToTime(datetime string, layout ...string) int64

StrToTime Parse English textual datetime description into a Unix timestamp. The default layout is: 2006-01-02 15:04:05.

func StringsUnique

func StringsUnique(a []string) []string

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

func StripSlashes

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

func Uint16sUnique(a []uint16) []uint16

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

func Uint32sUnique

func Uint32sUnique(a []uint32) []uint32

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

func Uint64sUnique

func Uint64sUnique(a []uint64) []uint64

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

func Uint8sUnique

func Uint8sUnique(a []uint8) []uint8

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

func UintsUnique

func UintsUnique(a []uint) []uint

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

func UpdateSQL

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 VersionCompare added in v4.0.5

func VersionCompare(rangeVer, curVer string) bool

VersionCompare compares semantic versions range, support: >, >=, =, !=, <, <=, | (or), & (and) eg: 1.0.0, =1.0.0, >2.0.0, >=1.0.0&<2.0.0, <2.0.0|>3.0.0, !=4.0.4

func WeekAround added in v4.0.3

func WeekAround() (monday, sunday string)

WeekAround returns the date of monday and sunday for current week

Types

type BufferPool added in v4.0.3

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

BufferPool type of buffer pool

func NewBufferPool added in v4.0.3

func NewBufferPool(cap int64) *BufferPool

NewBufferPool returns a new buffer pool

func (*BufferPool) Get added in v4.0.3

func (b *BufferPool) Get() *bytes.Buffer

Get return a buffer

func (*BufferPool) Put added in v4.0.3

func (b *BufferPool) Put(buf *bytes.Buffer)

Put put a buffer to pool

type CDATA

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

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

MarshalXML encodes the receiver as zero or more XML elements.

type EMail

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

EMail email

type EMailDialer

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

EMailDialer email dialer

func Mailer

func Mailer(name ...string) *EMailDialer

Mailer returns an email dialer.

func (*EMailDialer) Send

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

Send send an email.

type EMailOption

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

EMailOption configures how we set up the email

func WithEMailCharset

func WithEMailCharset(s string) EMailOption

WithEMailCharset specifies the `Charset` to email.

func WithEMailContentType

func WithEMailContentType(s string) EMailOption

WithEMailContentType specifies the `ContentType` to email.

func WithEMailEncoding

func WithEMailEncoding(e gomail.Encoding) EMailOption

WithEMailEncoding specifies the `Encoding` to email.

type EnvValue

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

Env config value

func Env

func Env(key string) *EnvValue

Env returns an env value

func (*EnvValue) Bool

func (e *EnvValue) Bool(defaultValue ...bool) bool

Bool returns a value of bool.

func (*EnvValue) Float64

func (e *EnvValue) Float64(defaultValue ...float64) float64

Float64 returns a value of float64.

func (*EnvValue) Float64s

func (e *EnvValue) Float64s(defaultValue ...float64) []float64

Float64s returns a value of []float64.

func (*EnvValue) Int

func (e *EnvValue) Int(defaultValue ...int) int

Int returns a value of int.

func (*EnvValue) Int16

func (e *EnvValue) Int16(defaultValue ...int16) int16

Int16 returns a value of int16.

func (*EnvValue) Int16s

func (e *EnvValue) Int16s(defaultValue ...int16) []int16

Int16s returns a value of []int16.

func (*EnvValue) Int32

func (e *EnvValue) Int32(defaultValue ...int32) int32

Int32 returns a value of int32.

func (*EnvValue) Int32s

func (e *EnvValue) Int32s(defaultValue ...int32) []int32

Int32s returns a value of []int32.

func (*EnvValue) Int64

func (e *EnvValue) Int64(defaultValue ...int64) int64

Int64 returns a value of int64.

func (*EnvValue) Int64s

func (e *EnvValue) Int64s(defaultValue ...int64) []int64

Int64s returns a value of []int64.

func (*EnvValue) Int8

func (e *EnvValue) Int8(defaultValue ...int8) int8

Int8 returns a value of int8.

func (*EnvValue) Int8s

func (e *EnvValue) Int8s(defaultValue ...int8) []int8

Int8s returns a value of []int8.

func (*EnvValue) Ints

func (e *EnvValue) Ints(defaultValue ...int) []int

Ints returns a value of []int.

func (*EnvValue) Map

func (e *EnvValue) Map() map[string]interface{}

Map returns a value of map[string]interface{}.

func (*EnvValue) String

func (e *EnvValue) String(defaultValue ...string) string

String returns a value of string.

func (*EnvValue) Strings

func (e *EnvValue) Strings(defaultValue ...string) []string

Strings returns a value of []string.

func (*EnvValue) Time

func (e *EnvValue) Time(layout string, defaultValue ...time.Time) time.Time

Time returns a value of time.Time. Layout is required when the env value is a string.

func (*EnvValue) Uint

func (e *EnvValue) Uint(defaultValue ...uint) uint

Uint returns a value of uint.

func (*EnvValue) Uint16

func (e *EnvValue) Uint16(defaultValue ...uint16) uint16

Uint16 returns a value of uint16.

func (*EnvValue) Uint16s

func (e *EnvValue) Uint16s(defaultValue ...uint16) []uint16

Uint16s returns a value of []uint16.

func (*EnvValue) Uint32

func (e *EnvValue) Uint32(defaultValue ...uint32) uint32

Uint32 returns a value of uint32.

func (*EnvValue) Uint32s

func (e *EnvValue) Uint32s(defaultValue ...uint32) []uint32

Uint32s returns a value of []uint32.

func (*EnvValue) Uint64

func (e *EnvValue) Uint64(defaultValue ...uint64) uint64

Uint64 returns a value of uint64.

func (*EnvValue) Uint64s

func (e *EnvValue) Uint64s(defaultValue ...uint64) []uint64

Uint64s returns a value of []uint64.

func (*EnvValue) Uint8

func (e *EnvValue) Uint8(defaultValue ...uint8) uint8

Uint8 returns a value of uint8.

func (*EnvValue) Uint8s

func (e *EnvValue) Uint8s(defaultValue ...uint8) []uint8

Uint8s returns a value of []uint8.

func (*EnvValue) Uints

func (e *EnvValue) Uints(defaultValue ...uint) []uint

Uints returns a value of []uint.

func (*EnvValue) Unmarshal

func (e *EnvValue) Unmarshal(dest interface{}) error

Unmarshal attempts to unmarshal the Tree into a Go struct pointed by dest.

type GinValidator added in v4.2.0

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

GinValidator validator for gin

func NewGinValidator added in v4.0.3

func NewGinValidator() *GinValidator

NewGinValidator returns a validator for gin

func (*GinValidator) Engine added in v4.2.0

func (v *GinValidator) Engine() interface{}

Engine returns the underlying validator engine which powers the default Validator instance. This is useful if you want to register custom validations or struct level validations. See validator GoDoc for more info - https://godoc.org/gopkg.in/go-playground/validator.v10

func (*GinValidator) ValidateStruct added in v4.2.0

func (v *GinValidator) ValidateStruct(obj interface{}) error

ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.

type HTTPClient

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

HTTPClient http client

func NewHTTPClient

func NewHTTPClient(options ...HTTPClientOption) *HTTPClient

NewHTTPClient returns a new http client

func (*HTTPClient) Get

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

Get http get request

func (*HTTPClient) Post

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

Post http post request

type HTTPClientOption

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

HTTPClientOption configures how we set up the http client

func WithHTTPDefaultTimeout

func WithHTTPDefaultTimeout(d time.Duration) HTTPClientOption

WithHTTPDefaultTimeout specifies the `DefaultTimeout` to http client.

func WithHTTPDialFallbackDelay

func WithHTTPDialFallbackDelay(d time.Duration) HTTPClientOption

WithHTTPDialFallbackDelay specifies the `FallbackDelay` to net.Dialer.

func WithHTTPDialKeepAlive

func WithHTTPDialKeepAlive(d time.Duration) HTTPClientOption

WithHTTPDialKeepAlive specifies the `KeepAlive` to net.Dialer.

func WithHTTPDialTimeout

func WithHTTPDialTimeout(d time.Duration) HTTPClientOption

WithHTTPDialTimeout specifies the `DialTimeout` to net.Dialer.

func WithHTTPExpectContinueTimeout

func WithHTTPExpectContinueTimeout(d time.Duration) HTTPClientOption

WithHTTPExpectContinueTimeout specifies the `ExpectContinueTimeout` to http client.

func WithHTTPIdleConnTimeout

func WithHTTPIdleConnTimeout(d time.Duration) HTTPClientOption

WithHTTPIdleConnTimeout specifies the `IdleConnTimeout` to http client.

func WithHTTPMaxConnsPerHost

func WithHTTPMaxConnsPerHost(n int) HTTPClientOption

WithHTTPMaxConnsPerHost specifies the `MaxConnsPerHost` to http client.

func WithHTTPMaxIdleConns

func WithHTTPMaxIdleConns(n int) HTTPClientOption

WithHTTPMaxIdleConns specifies the `MaxIdleConns` to http client.

func WithHTTPMaxIdleConnsPerHost

func WithHTTPMaxIdleConnsPerHost(n int) HTTPClientOption

WithHTTPMaxIdleConnsPerHost specifies the `MaxIdleConnsPerHost` to http client.

func WithHTTPTLSConfig

func WithHTTPTLSConfig(c *tls.Config) HTTPClientOption

WithHTTPTLSConfig specifies the `TLSClientConfig` to http client.

func WithHTTPTLSHandshakeTimeout

func WithHTTPTLSHandshakeTimeout(d time.Duration) HTTPClientOption

WithHTTPTLSHandshakeTimeout specifies the `TLSHandshakeTimeout` to http client.

type HTTPRequestOption

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

HTTPRequestOption configures how we set up the http request

func WithRequestClose

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

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

WithRequestCookies specifies the cookies to http request.

func WithRequestHeader

func WithRequestHeader(key, value string) HTTPRequestOption

WithRequestHeader specifies the header to http request.

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) HTTPRequestOption

WithRequestTimeout specifies the timeout to http request.

func WithZipkinSpanTag

func WithZipkinSpanTag(key, value string) HTTPRequestOption

WithZipkinSpanTag specifies the zipkin span tag to zipkin http request.

type HashAlgo added in v4.1.1

type HashAlgo string
const (
	AlgoMD5    HashAlgo = "md5"
	AlgoSha1   HashAlgo = "sha1"
	AlgoSha224 HashAlgo = "sha224"
	AlgoSha256 HashAlgo = "sha256"
	AlgoSha384 HashAlgo = "sha384"
	AlgoSha512 HashAlgo = "sha512"
)

type Int16Slice

type Int16Slice []int16

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

func (Int16Slice) Len

func (p Int16Slice) Len() int

func (Int16Slice) Less

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

func (Int16Slice) Swap

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

type Int32Slice

type Int32Slice []int32

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

func (Int32Slice) Len

func (p Int32Slice) Len() int

func (Int32Slice) Less

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

func (Int32Slice) Swap

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

type Int64Slice

type Int64Slice []int64

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

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

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

func (Int64Slice) Swap

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

type Int8Slice

type Int8Slice []int8

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

func (Int8Slice) Len

func (p Int8Slice) Len() int

func (Int8Slice) Less

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

func (Int8Slice) Swap

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

type RedisConn

type RedisConn struct {
	redis.Conn
}

RedisConn redis connection resource

func (RedisConn) Close

func (r RedisConn) Close()

Close close connection resorce

type RedisPoolResource

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

RedisPoolResource redis pool resource

func Redis

func Redis(name ...string) *RedisPoolResource

Redis returns a redis pool.

func (*RedisPoolResource) Get

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

Get get a connection resource from the pool.

func (*RedisPoolResource) Put

func (r *RedisPoolResource) Put(rc RedisConn)

Put returns a connection resource to the pool.

type Uint16Slice

type Uint16Slice []uint16

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

func (Uint16Slice) Len

func (p Uint16Slice) Len() int

func (Uint16Slice) Less

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

func (Uint16Slice) Swap

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

type Uint32Slice

type Uint32Slice []uint32

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

func (Uint32Slice) Len

func (p Uint32Slice) Len() int

func (Uint32Slice) Less

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

func (Uint32Slice) Swap

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

type Uint64Slice

type Uint64Slice []uint64

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

func (Uint64Slice) Len

func (p Uint64Slice) Len() int

func (Uint64Slice) Less

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

func (Uint64Slice) Swap

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

type Uint8Slice

type Uint8Slice []uint8

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

func (Uint8Slice) Len

func (p Uint8Slice) Len() int

func (Uint8Slice) Less

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

func (Uint8Slice) Swap

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

type UintSlice

type UintSlice []uint

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

func (UintSlice) Len

func (p UintSlice) Len() int

func (UintSlice) Less

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

func (UintSlice) Swap

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

type X

type X map[string]interface{}

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

type ZipkinHTTPClient

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

ZipkinHTTPClient zipkin http client

func (*ZipkinHTTPClient) Get

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

Get zipkin http get request

func (*ZipkinHTTPClient) Post

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

Post zipkin http post request

type ZipkinHTTPClientOption

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

ZipkinHTTPClientOption configures how we set up the zipkin http client

func WithZipkinClientOptions

func WithZipkinClientOptions(options ...zipkinHTTP.ClientOption) ZipkinHTTPClientOption

WithZipkinClientOptions specifies the `Options` to zipkin http client.

func WithZipkinHTTPClient

func WithZipkinHTTPClient(options ...HTTPClientOption) ZipkinHTTPClientOption

WithZipkinHTTPClient specifies the `Client` to zipkin http client.

func WithZipkinHTTPTransport

func WithZipkinHTTPTransport(options ...zipkinHTTP.TransportOption) ZipkinHTTPClientOption

WithZipkinHTTPTransport specifies the `Transport` to zipkin http client transport.

type ZipkinReporterOption

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

ZipkinReporterOption configures how we set up the zipkin reporter

func WithZipkinReporterClient

func WithZipkinReporterClient(options ...HTTPClientOption) ZipkinReporterOption

WithZipkinReporterClient specifies the `Client` to zipkin reporter.

func WithZipkinReporterOptions

func WithZipkinReporterOptions(options ...zipkinHTTPReporter.ReporterOption) ZipkinReporterOption

WithZipkinReporterOptions specifies the `Options` to zipkin reporter.

type ZipkinTracer

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

ZipkinTracer zipkin tracer

func NewZipkinTracer

func NewZipkinTracer(r reporter.Reporter, options ...zipkin.TracerOption) (*ZipkinTracer, error)

NewZipkinTracer returns a zipkin tracer

func (*ZipkinTracer) HTTPClient

func (z *ZipkinTracer) HTTPClient(options ...ZipkinHTTPClientOption) (*ZipkinHTTPClient, error)

HTTPClient returns a new zipkin http client

func (*ZipkinTracer) Start

func (z *ZipkinTracer) Start(req *http.Request) zipkin.Span

Start returns a new zipkin span

use as below:

span := yiigo.ZTracer.Start(r) defer span.Finish()

... do something with span, eg: span.Tag()

ctx := zipkin.NewContext(req.Context(), span) req = req.WithContext(ctx)

Jump to

Keyboard shortcuts

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