Documentation ¶
Index ¶
- Constants
- func AddSlashes(s string) string
- func Date(timestamp int64, layout ...string) string
- func Float64sUnique(a []float64) []float64
- func GenerateRSAKey(bitSize int, blockType PemBlockType) (privateKey, publicKey []byte, err error)
- func HMAC(algo HashAlgo, s, key string) string
- func HTTPDo(ctx context.Context, method, reqURL string, body io.Reader, ...) (*http.Response, error)
- func HTTPGet(ctx context.Context, reqURL string, options ...HTTPOption) (*http.Response, error)
- func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
- func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) (*http.Response, error)
- func HTTPUpload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error)
- func Hash(algo HashAlgo, s string) string
- func IP2Long(ip string) uint32
- func InArray(needle interface{}, haystack []interface{}) bool
- func InFloat64s(needle float64, haystack []float64) bool
- func InInt64s(needle int64, haystack []int64) bool
- func InInts(needle int, haystack []int) bool
- func InStrings(needle string, haystack []string) bool
- func Init(options ...InitOption)
- func Int64sUnique(a []int64) []int64
- func IntsUnique(a []int) []int
- func LoadEnv(options ...EnvOption) error
- func Logger(name ...string) *zap.Logger
- func Long2IP(ip uint32) string
- func MD5(s string) string
- func Mongo(name ...string) *mongo.Client
- func MyTimeEncoder(t time.Time, e zapcore.PrimitiveArrayEncoder)
- func NSQDeferredPublish(topic string, msg NSQMessage, duration time.Duration) error
- func NSQPublish(topic string, msg NSQMessage) error
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func NextAttemptDuration(attempts uint16) time.Duration
- func PKCS5Padding(cipherText []byte, blockSize int) []byte
- func PKCS5Unpadding(plainText []byte, blockSize int) []byte
- func QuoteMeta(s string) string
- func RSADecrypt(cipherText, privateKey []byte) ([]byte, error)
- func RSADecryptOEAP(cipherText, privateKey []byte) ([]byte, error)
- func RSAEncrypt(plainText, publicKey []byte) ([]byte, error)
- func RSAEncryptOEAP(plainText, publicKey []byte) ([]byte, error)
- func RSAPemToSSH(pemPubKey []byte) (sshRSA []byte, fingerprint string, err error)
- func RSASignWithSha256(data, privateKey []byte) ([]byte, error)
- func RSAVerifyWithSha256(data, signature, publicKey []byte) error
- func SHA1(s string) string
- func SearchInt64s(a []int64, x int64) int
- func SortInt64s(a []int64)
- func StrToTime(datetime string, layout ...string) int64
- func StringsUnique(a []string) []string
- func StripSlashes(s string) string
- func VersionCompare(rangeVer, curVer string) (bool, error)
- func WeekAround(t time.Time) (monday, sunday string)
- func ZeroPadding(cipherText []byte, blockSize int) []byte
- func ZeroUnPadding(plainText []byte) []byte
- type AESCrypto
- type CDATA
- type EnvEventFunc
- type EnvOption
- type GRPCConn
- type GRPCDialFunc
- type GRPCPool
- type HTTPClient
- type HTTPOption
- type HashAlgo
- type InitOption
- type Int64Slice
- type LoggerOption
- type NSQConsumer
- type NSQLogger
- type NSQMessage
- type NSQOption
- type PaddingMode
- type PemBlockType
- type PoolOption
- type RedisConn
- type RedisOption
- type RedisPool
- type SSHKey
- type UploadField
- type UploadForm
- type Validator
- type X
Constants ¶
const Default = "default"
Default defines for `default` name
Variables ¶
This section is empty.
Functions ¶
func AddSlashes ¶
AddSlashes returns a string with backslashes added before characters that need to be escaped.
func Date ¶
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 ¶
Float64sUnique takes an input slice of float64s and returns a new slice of float64s without duplicate values.
func GenerateRSAKey ¶
func GenerateRSAKey(bitSize int, blockType PemBlockType) (privateKey, publicKey []byte, err error)
GenerateRSAKey returns rsa private and public key.
func HTTPDo ¶
func HTTPDo(ctx context.Context, method, reqURL string, body io.Reader, options ...HTTPOption) (*http.Response, error)
HTTPDo sends an HTTP request and returns an HTTP response
func HTTPPost ¶
func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
HTTPPost issues a POST to the specified URL.
func HTTPPostForm ¶
func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) (*http.Response, error)
HTTPPostForm issues a POST to the specified URL, with data's keys and values URL-encoded as the request body.
func HTTPUpload ¶
func HTTPUpload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error)
HTTPUpload issues a UPLOAD to the specified URL.
func IP2Long ¶
IP2Long converts a string containing an (IPv4) Internet Protocol dotted address into an uint32 integer.
func InArray ¶
func InArray(needle interface{}, haystack []interface{}) bool
InArray checks if a value of interface{} exists in a slice of []interface{}.
func InFloat64s ¶
InFloat64s checks if a value of float64 exists in a slice of []float64.
func Int64sUnique ¶
Int64sUnique takes an input slice of int64s and returns a new slice of int64s without duplicate values.
func IntsUnique ¶
IntsUnique takes an input slice of ints and returns a new slice of ints without duplicate values.
func LoadEnv ¶
LoadEnv will read your env file(s) and load them into ENV for this process. It will default to loading .env in the current path if not specifies the filename.
func Long2IP ¶
Long2IP converts an uint32 integer address into a string in (IPv4) Internet standard dotted format.
func MyTimeEncoder ¶
func MyTimeEncoder(t time.Time, e zapcore.PrimitiveArrayEncoder)
MyTimeEncoder zap time encoder.
func NSQDeferredPublish ¶
func NSQDeferredPublish(topic string, msg NSQMessage, duration time.Duration) error
NSQDeferredPublish synchronously publishes a message body to the specified topic where the message will queue at the channel level until the timeout expires.
func NSQPublish ¶
func NSQPublish(topic string, msg NSQMessage) error
NSQPublish synchronously publishes a message body to the specified topic.
func NewECBDecrypter ¶
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
func NewECBEncrypter ¶
NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.
func NextAttemptDuration ¶
NextAttemptDuration helper for attempt duration.
func PKCS5Padding ¶
func PKCS5Unpadding ¶
func QuoteMeta ¶
QuoteMeta returns a version of str with a backslash character (\) before every character that is among these: . \ + * ? [ ^ ] ( $ )
func RSADecrypt ¶
RSADecrypt rsa decrypt with PKCS #1 v1.5
func RSADecryptOEAP ¶
RSADecryptOEAP rsa decrypt with PKCS #1 OEAP.
func RSAEncrypt ¶
RSAEncrypt rsa encrypt with PKCS #1 v1.5
func RSAEncryptOEAP ¶
RSAEncryptOEAP rsa encrypt with PKCS #1 OEAP.
func RSAPemToSSH ¶
RSAPemToSSH converts rsa public key from pem to ssh-rsa. Note: value ends with `\n`
func RSASignWithSha256 ¶
RSASignWithSha256 returns rsa signature with sha256.
func RSAVerifyWithSha256 ¶
RSAVerifyWithSha256 verifies rsa signature with sha256.
func SearchInt64s ¶
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 StrToTime ¶
StrToTime Parse English textual datetime description into a Unix timestamp. The default layout is: 2006-01-02 15:04:05.
func StringsUnique ¶
StringsUnique takes an input slice of strings and returns a new slice of strings without duplicate values.
func StripSlashes ¶
StripSlashes returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\).
func VersionCompare ¶
VersionCompare compares semantic versions range, support: >, >=, =, !=, <, <=, | (or), & (and). Param `rangeVer` 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 ¶
WeekAround returns the date of monday and sunday for current week.
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type AESCrypto ¶
type AESCrypto interface { // Encrypt encrypts the plain text. Encrypt(plainText []byte) ([]byte, error) // Decrypt decrypts the cipher text. Decrypt(cipherText []byte) ([]byte, error) }
AESCrypto is the interface for aes crypto.
func NewCBCCrypto ¶
func NewCBCCrypto(key, iv []byte, mode PaddingMode) AESCrypto
NewCBCCrypto returns a new aes-cbc crypto.
func NewCFBCrypto ¶
NewCFBCrypto returns a new aes-cfb crypto
func NewCTRCrypto ¶
NewCTRCrypto returns a new aes-ctr crypto
func NewECBCrypto ¶
func NewECBCrypto(key []byte, mode PaddingMode) AESCrypto
NewECBCrypto returns a new aes-ecb crypto.
func NewGCMCrypto ¶
NewGCMCrypto returns a new aes-gcm crypto
func NewOFBCrypto ¶
NewOFBCrypto returns a new aes-ofb crypto
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 ¶
MarshalXML encodes the receiver as zero or more XML elements.
type EnvEventFunc ¶
EnvEventFunc the function that runs each time env change occurs.
type EnvOption ¶
type EnvOption func(e *environment)
EnvOption configures how we set up env file.
func WithEnvWatcher ¶
func WithEnvWatcher(fn ...EnvEventFunc) EnvOption
WithEnvWatcher watching and re-reading env file.
type GRPCDialFunc ¶
type GRPCDialFunc func() (*grpc.ClientConn, error)
GRPCDialFunc grpc dial function
type GRPCPool ¶
type GRPCPool interface { // Get returns a connection resource from the pool. // Context with timeout can specify the wait timeout for pool. Get(ctx context.Context) (*GRPCConn, error) // Put returns a connection resource to the pool. Put(gc *GRPCConn) }
GRPCPool grpc pool resource
func NewGRPCPool ¶
func NewGRPCPool(dial GRPCDialFunc, options ...PoolOption) GRPCPool
NewGRPCPool returns a new grpc pool with dial func.
type HTTPClient ¶
type HTTPClient interface { // Do sends an HTTP request and returns an HTTP response. // Should use context to specify the timeout for request. Do(ctx context.Context, method, reqURL string, body io.Reader, options ...HTTPOption) (*http.Response, error) // Upload issues a UPLOAD to the specified URL. // Should use context to specify the timeout for request. Upload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error) }
HTTPClient is the interface for a http client.
func NewHTTPClient ¶
func NewHTTPClient(client *http.Client) HTTPClient
NewHTTPClient returns a new http client
type HTTPOption ¶
type HTTPOption func(s *httpSetting)
HTTPOption configures how we set up the http request.
func WithHTTPClose ¶
func WithHTTPClose() HTTPOption
WithHTTPClose specifies close the connection after replying to this request (for servers) or after sending this request and reading its response (for clients).
func WithHTTPCookies ¶
func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption
WithHTTPCookies specifies the cookies to http request.
func WithHTTPHeader ¶
func WithHTTPHeader(key, value string) HTTPOption
WithHTTPHeader specifies the header to http request.
type InitOption ¶
type InitOption func(s *initSetting)
InitOption configures how we set up the yiigo initialization.
func WithLogger ¶
func WithLogger(name, logfile string, options ...LoggerOption) InitOption
WithLogger register logger.
func WithMongo ¶
func WithMongo(name string, dsn string) InitOption
WithMongo register mongodb. [DSN] mongodb://localhost:27017/?connectTimeoutMS=10000&minPoolSize=10&maxPoolSize=20&maxIdleTimeMS=60000&readPreference=primary [reference] https://docs.mongodb.com/manual/reference/connection-string
func WithNSQ ¶
func WithNSQ(nsqd string, lookupd []string, options ...NSQOption) InitOption
WithNSQ initialize the nsq.
func WithRedis ¶
func WithRedis(name, address string, options ...RedisOption) InitOption
WithRedis register redis.
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 LoggerOption ¶
type LoggerOption func(s *loggerSetting)
LoggerOption configures how we set up the logger.
func WithLogCompress ¶
func WithLogCompress() LoggerOption
WithLogCompress specifies the `Compress` for logger.
func WithLogMaxAge ¶
func WithLogMaxAge(n int) LoggerOption
WithLogMaxAge specifies the `MaxAge(days)` for logger.
func WithLogMaxBackups ¶
func WithLogMaxBackups(n int) LoggerOption
WithLogMaxBackups specifies the `MaxBackups` for logger.
func WithLogMaxSize ¶
func WithLogMaxSize(n int) LoggerOption
WithLogMaxSize specifies the `MaxSize(Mi)` for logger.
func WithLogStdErr ¶
func WithLogStdErr() LoggerOption
WithLogStdErr specifies stderr output for logger.
type NSQConsumer ¶
NSQConsumer NSQ consumer
type NSQMessage ¶
NSQMessage NSQ message
type NSQOption ¶
type NSQOption func(s *nsqSetting)
NSQOption configures how we set up the nsq config.
func WithLookupdPollInterval ¶
WithLookupdPollInterval specifies the `LookupdPollInterval` for nsq config.
func WithMaxInFlight ¶
WithMaxInFlight specifies the `MaxInFlight` for nsq config.
func WithNSQConsumer ¶
func WithNSQConsumer(consumer NSQConsumer) NSQOption
WithNSQConsumer specifies the consumer for nsq.
func WithRDYRedistributeInterval ¶
WithRDYRedistributeInterval specifies the `RDYRedistributeInterval` for nsq config.
type PaddingMode ¶
type PaddingMode string
PaddingMode aes padding mode
const ( // ZERO zero padding mode ZERO PaddingMode = "ZERO" // PKCS5 PKCS#5 padding mode PKCS5 PaddingMode = "PKCS#5" // PKCS7 PKCS#7 padding mode PKCS7 PaddingMode = "PKCS#7" )
type PemBlockType ¶
type PemBlockType string
PemBlockType pem block type which taken from the preamble.
const ( // RSAPKCS1 private key in PKCS#1 RSAPKCS1 PemBlockType = "RSA PRIVATE KEY" // RSAPKCS8 private key in PKCS#8 RSAPKCS8 PemBlockType = "PRIVATE KEY" )
type PoolOption ¶
type PoolOption func(s *poolSetting)
PoolOption configures how we set up the pool.
func WithPoolIdleTimeout ¶
func WithPoolIdleTimeout(duration time.Duration) PoolOption
WithPoolIdleTimeout specifies the maximum amount of time a connection may be idle. An idleTimeout of 0 means that there is no timeout.
func WithPoolLimit ¶
func WithPoolLimit(limit int) PoolOption
WithPoolLimit specifies the extent to which the pool can be resized in the future. You cannot resize the pool beyond poolLimit.
func WithPoolPrefill ¶
func WithPoolPrefill(prefill int) PoolOption
WithPoolPrefill specifies how many resources can be opened in parallel.
func WithPoolSize ¶
func WithPoolSize(size int) PoolOption
WithPoolSize specifies the number of possible resources in the pool.
type RedisOption ¶
type RedisOption func(s *redisSetting)
RedisOption configures how we set up the redis.
func WithRedisConnTimeout ¶
func WithRedisConnTimeout(t time.Duration) RedisOption
WithRedisConnTimeout specifies the `ConnectTimeout` for redis.
func WithRedisDatabase ¶
func WithRedisDatabase(db int) RedisOption
WithRedisDatabase specifies the database for redis.
func WithRedisPool ¶
func WithRedisPool(options ...PoolOption) RedisOption
WithRedisPool specifies the pool for redis.
func WithRedisReadTimeout ¶
func WithRedisReadTimeout(t time.Duration) RedisOption
WithRedisReadTimeout specifies the `ReadTimeout` for redis.
func WithRedisWriteTimeout ¶
func WithRedisWriteTimeout(t time.Duration) RedisOption
WithRedisWriteTimeout specifies the `WriteTimeout` for redis.
type RedisPool ¶
type RedisPool interface { // Get returns a connection resource from the pool. // Context with timeout can specify the wait timeout for pool. Get(ctx context.Context) (*RedisConn, error) // Put returns a connection resource to the pool. Put(rc *RedisConn) }
RedisPool redis pool resource
type SSHKey ¶
func GenerateSSHKey ¶
GenerateSSHKey returns ssh id_rsa and id_rsa.pub. Note: id_rsa.pub ends with `\n`
type UploadField ¶
type UploadField func(f *uploadform)
UploadField configures how we set up the upload from.
func WithFileField ¶
func WithFileField(fieldname, filename string, body []byte) UploadField
WithFileField specifies the file field to upload from.
func WithFormField ¶
func WithFormField(fieldname, fieldvalue string) UploadField
WithFormField specifies the form field to upload from.
type UploadForm ¶
type UploadForm interface { // Write writes fields to multipart writer Write(w *multipart.Writer) error }
UploadForm is the interface for http upload
func NewUploadForm ¶
func NewUploadForm(fields ...UploadField) UploadForm
NewUploadForm returns an upload form
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator a validator which can be used for Gin.
func NewValidator ¶
func NewValidator() *Validator
NewValidator returns a new validator. Used for Gin: binding.Validator = yiigo.NewValidator()
func (*Validator) Engine ¶
func (v *Validator) 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 (*Validator) ValidateStruct ¶
ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.