Documentation
¶
Index ¶
- Constants
- Variables
- func Bind(source any, v any)
- func BindJson(source string, v any)
- func Copy(toValue interface{}, fromValue interface{}) (err error)
- func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error)
- func FormatMoney(number float64, decimals uint, decPoint, thousandsSep string) string
- func HttpResponseJson(g *gin.Context, i interface{}, err error)
- func IsNil(i interface{}) bool
- func JsonMinify(jsonB []byte) ([]byte, error)
- func LogERL(key string, format string, args ...interface{})
- func LogErr(err error)
- func LogIRL(key string, format string, args ...interface{})
- func LogJ(arg interface{})
- func LogJI(arg interface{})
- func LogWRL(key string, format string, args ...interface{})
- func ToJson(data interface{}) string
- func ToJsonIndent(data interface{}) string
- type Crypto
- type EncryptWith
- type FieldNameMapping
- type HttpBuilder
- func (h *HttpBuilder) AddHeader(name string, value string)
- func (h *HttpBuilder) Default()
- func (h *HttpBuilder) Get(endPoint string, urlQuery interface{}, body interface{}, ...) (fullUrl string, responseStatusCode int, responseBody string, err error)
- func (h *HttpBuilder) GetCookie() (jar http.CookieJar)
- func (h *HttpBuilder) GetRequest() *http.Response
- func (h *HttpBuilder) GetResponse() *http.Response
- func (h *HttpBuilder) MultipartEnable()
- func (h *HttpBuilder) Post(endPoint string, body interface{}, option HttpBuilderOptions) (fullUrl string, responseStatusCode int, responseBody string, err error)
- func (h *HttpBuilder) SetBasicAuth(username, password string)
- func (h *HttpBuilder) SetClient(client *http.Client)
- func (h *HttpBuilder) SetUrl(url string)
- func (h *HttpBuilder) UseCookie(jar *cookiejar.Jar) error
- func (h *HttpBuilder) UseProxy(proxyServer string) error
- type HttpBuilderOptions
- type Option
- type RateLimiter
- type RsaEncrypt
- type RsaKeys
- func (r *RsaKeys) Load() (err error)
- func (r *RsaKeys) LoadPrivateKey() (err error)
- func (r *RsaKeys) LoadPublicKey() (err error)
- func (r *RsaKeys) SavePKCS1() (err error)
- func (r *RsaKeys) SavePKCS8() (err error)
- func (r *RsaKeys) SavePrivateKeyPKCS1() (err error)
- func (r *RsaKeys) SavePrivateKeyPKCS8() (err error)
- func (r *RsaKeys) SavePublicKeyPKCS1() (err error)
- func (r *RsaKeys) SavePublicKeyPKIX() (err error)
- func (r *RsaKeys) SetPrivateKey(privateKey []byte) (err error)
- func (r *RsaKeys) SetPrivateKeyString(privateKey string) (err error)
- func (r *RsaKeys) SetPublicKey(publicKey []byte) (err error)
- func (r *RsaKeys) SetPublicKeyString(publicKey string) (err error)
- type RsaSign
- type SagaLogger
- type SagaState
- type TypeConverter
Constants ¶
const ( // Some default converter types for a nicer syntax String string = "" Bool bool = false Int int = 0 Float32 float32 = 0 Float64 float64 = 0 )
These flags define options for tag handling
const ( RSA512 = iota RSA1024 RSA2048 RSA4096 )
Variables ¶
var ( ErrInvalidCopyDestination = errors.New("copy destination must be non-nil and addressable") ErrInvalidCopyFrom = errors.New("copy from must be non-nil and addressable") ErrMapKeyNotMatch = errors.New("map's key type doesn't match") ErrNotSupported = errors.New("not supported") ErrFieldNameTagStartNotUpperCase = errors.New("copier field name tag must be start upper case") )
var ( Log = golog.New() LogD = Log.Debugf LogI = Log.Infof LogW = Log.Warnf LogE = Log.Errorf LogF = Log.Fatalf Logf = Log.Logf )
var LogRateLimiter = NewRateLimiter(30 * time.Second)
Global rate limiter for logging with default interval
Functions ¶
func CopyWithOption ¶
CopyWithOption copy with option
func FormatMoney ¶
func HttpResponseJson ¶
func JsonMinify ¶
return a minified JSON input string return an error encountered during minifiying or reading minified bytes
func LogERL ¶ added in v1.0.4
LogERL (Log Error with Rate Limit) logs an error message with rate limiting key: unique identifier for this log type (e.g., "rabbitmq-channel-closed") format: printf-style format string args: arguments for the format string
func LogIRL ¶ added in v1.0.4
LogIRL (Log Info with Rate Limit) logs an info message with rate limiting
func LogWRL ¶ added in v1.0.4
LogWRL (Log Warning with Rate Limit) logs a warning message with rate limiting
func ToJson ¶
func ToJson(data interface{}) string
Encode json from object to JSON and beautify the output.
func ToJsonIndent ¶
func ToJsonIndent(data interface{}) string
Encode json from object to JSON and beautify the output.
Types ¶
type Crypto ¶
type Crypto struct {
Rsa *RsaKeys
}
Crypto structure
func (*Crypto) Decrypt ¶
func (c *Crypto) Decrypt(encryption *RsaEncrypt) (err error)
Decrypt encrypted message to plain text.
func (*Crypto) Encrypt ¶
func (c *Crypto) Encrypt(encryption *RsaEncrypt) (err error)
func (*Crypto) VerifySign ¶
Verify signature and match with payload.
type FieldNameMapping ¶
type HttpBuilder ¶
type HttpBuilder struct {
// contains filtered or unexported fields
}
Type for saving oy builder params.
func (*HttpBuilder) AddHeader ¶
func (h *HttpBuilder) AddHeader(name string, value string)
Setting up header name and value.
func (*HttpBuilder) Default ¶
func (h *HttpBuilder) Default()
Set http client with default configuration.
func (*HttpBuilder) Get ¶
func (h *HttpBuilder) Get(endPoint string, urlQuery interface{}, body interface{}, option HttpBuilderOptions) (fullUrl string, responseStatusCode int, responseBody string, err error)
Get request.
func (*HttpBuilder) GetCookie ¶ added in v1.0.4
func (h *HttpBuilder) GetCookie() (jar http.CookieJar)
func (*HttpBuilder) GetRequest ¶
func (h *HttpBuilder) GetRequest() *http.Response
func (*HttpBuilder) GetResponse ¶
func (h *HttpBuilder) GetResponse() *http.Response
func (*HttpBuilder) MultipartEnable ¶
func (h *HttpBuilder) MultipartEnable()
func (*HttpBuilder) Post ¶
func (h *HttpBuilder) Post(endPoint string, body interface{}, option HttpBuilderOptions) (fullUrl string, responseStatusCode int, responseBody string, err error)
Post request.
func (*HttpBuilder) SetBasicAuth ¶
func (h *HttpBuilder) SetBasicAuth(username, password string)
Set Basic Auth
func (*HttpBuilder) SetClient ¶
func (h *HttpBuilder) SetClient(client *http.Client)
Manual set http builder.
func (*HttpBuilder) UseCookie ¶ added in v1.0.4
func (h *HttpBuilder) UseCookie(jar *cookiejar.Jar) error
func (*HttpBuilder) UseProxy ¶ added in v1.0.4
func (h *HttpBuilder) UseProxy(proxyServer string) error
type HttpBuilderOptions ¶
type Option ¶
type Option struct {
// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
IgnoreEmpty bool
CaseSensitive bool
DeepCopy bool
Converters []TypeConverter
// Custom field name mappings to copy values with different names in `fromValue` and `toValue` types.
// Examples can be found in `copier_field_name_mapping_test.go`.
FieldNameMapping []FieldNameMapping
}
Option sets copy options
type RateLimiter ¶ added in v1.0.4
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides thread-safe rate limiting for operations
func NewRateLimiter ¶ added in v1.0.4
func NewRateLimiter(minInterval time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter with the specified minimum interval between operations
func (*RateLimiter) Allow ¶ added in v1.0.4
func (rl *RateLimiter) Allow(key string) bool
Allow checks if an operation with the given key is allowed based on the rate limit Returns true if enough time has passed since the last operation with this key
func (*RateLimiter) Reset ¶ added in v1.0.4
func (rl *RateLimiter) Reset(key string)
Reset clears the rate limiter history for a specific key
func (*RateLimiter) ResetAll ¶ added in v1.0.4
func (rl *RateLimiter) ResetAll()
ResetAll clears all rate limiter history
type RsaEncrypt ¶
type RsaEncrypt struct {
Hash crypto.Hash
Encryption EncryptWith
Message []byte
Encrypted []byte
}
Encryption / decryption setting
func (*RsaEncrypt) FromBase64 ¶
func (r *RsaEncrypt) FromBase64(encrypted string) (err error)
Get encrypted from base64.
type RsaKeys ¶
type RsaKeys struct {
PublicKey *rsa.PublicKey
PrivateKey *rsa.PrivateKey
PrivateKeyFile string
PublicKeyFile string
}
Handle load and save keys to memory/storage.
func (*RsaKeys) LoadPrivateKey ¶
Load file and setup private key.
func (*RsaKeys) LoadPublicKey ¶
Load file and setup public key.
func (*RsaKeys) SavePrivateKeyPKCS1 ¶
Save PrivateKey to storage in PKCS1.
func (*RsaKeys) SavePrivateKeyPKCS8 ¶
Save PrivateKey to storage in PKCS8 format.
func (*RsaKeys) SavePublicKeyPKCS1 ¶
Save PublicKey to storage in PKCS1.
func (*RsaKeys) SavePublicKeyPKIX ¶
Save PublicKey to storage in PKIX format.
func (*RsaKeys) SetPrivateKey ¶
Parses a PEM encoded private key.
func (*RsaKeys) SetPrivateKeyString ¶
Set the private key string.
func (*RsaKeys) SetPublicKey ¶
Parses a PEM encoded public key.
func (*RsaKeys) SetPublicKeyString ¶
Set the public key string.
type RsaSign ¶
A place for create or load signature ;
func (*RsaSign) FromBase64 ¶
Get signature as base64.
type SagaLogger ¶
func (*SagaLogger) Log ¶
func (sl *SagaLogger) Log(ctx context.Context, tx saga.Transaction) error
type TypeConverter ¶
type TypeConverter struct {
SrcType interface{}
DstType interface{}
Fn func(src interface{}) (dst interface{}, err error)
}