lets

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const (
	RSA512 = iota
	RSA1024
	RSA2048
	RSA4096
)

Variables

View Source
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")
)
View Source
var (
	Log  = golog.New()
	LogD = Log.Debugf
	LogI = Log.Infof
	LogW = Log.Warnf
	LogE = Log.Errorf
	LogF = Log.Fatalf
	Logf = Log.Logf
)

Functions

func Bind

func Bind(source any, v any)

func BindJson

func BindJson(source string, v any)

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func CopyWithOption

func CopyWithOption(toValue interface{}, fromValue interface{}, opt Option) (err error)

CopyWithOption copy with option

func FormatMoney

func FormatMoney(number float64, decimals uint, decPoint, thousandsSep string) string

func HttpResponseJson

func HttpResponseJson(g *gin.Context, i interface{}, err error)

func IsNil

func IsNil(i interface{}) bool

func JsonMinify

func JsonMinify(jsonB []byte) ([]byte, error)

return a minified JSON input string return an error encountered during minifiying or reading minified bytes

func LogErr added in v1.4.7

func LogErr(err error)

Log Error

func LogJ added in v1.4.7

func LogJ(arg interface{})

Log JSON

func LogJI added in v1.4.7

func LogJI(arg interface{})

Log as JSON with Indent

func ToJson

func ToJson(data interface{}) string

Encode json from object to JSON and beautify the output.

func ToJsonIndent added in v1.4.7

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) Generate

func (c *Crypto) Generate(keyType int, rsaKeys *RsaKeys) (err error)

Generate a pair of RSA keys.

func (*Crypto) Sign

func (c *Crypto) Sign(sign *RsaSign) (err error)

Sign payload and get signature.

func (*Crypto) VerifySign

func (c *Crypto) VerifySign(sign *RsaSign) (err error)

Verify signature and match with payload.

type EncryptWith

type EncryptWith int
const (
	PKCS1v15 EncryptWith = iota
	OAEP
)

type FieldNameMapping

type FieldNameMapping struct {
	SrcType interface{}
	DstType interface{}
	Mapping map[string]string
}

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, response string, err error)

Get request.

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, response 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) SetUrl

func (h *HttpBuilder) SetUrl(url string)

Set End Point

type HttpBuilderOptions

type HttpBuilderOptions struct {
	LogHeader      bool
	LogMethod      bool
	LogRequestBody bool
	LogResponse    bool
}

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 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.

func (*RsaEncrypt) ToBase64

func (r *RsaEncrypt) ToBase64() string

Get encrypted to 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) Load

func (r *RsaKeys) Load() (err error)

Load Keys file.

func (*RsaKeys) LoadPrivateKey

func (r *RsaKeys) LoadPrivateKey() (err error)

Load file and setup private key.

func (*RsaKeys) LoadPublicKey

func (r *RsaKeys) LoadPublicKey() (err error)

Load file and setup public key.

func (*RsaKeys) SavePKCS1

func (r *RsaKeys) SavePKCS1() (err error)

Save all keys into storage.

func (*RsaKeys) SavePKCS8

func (r *RsaKeys) SavePKCS8() (err error)

Save all keys into storage in PKCS8.

func (*RsaKeys) SavePrivateKeyPKCS1

func (r *RsaKeys) SavePrivateKeyPKCS1() (err error)

Save PrivateKey to storage in PKCS1.

func (*RsaKeys) SavePrivateKeyPKCS8

func (r *RsaKeys) SavePrivateKeyPKCS8() (err error)

Save PrivateKey to storage in PKCS8 format.

func (*RsaKeys) SavePublicKeyPKCS1

func (r *RsaKeys) SavePublicKeyPKCS1() (err error)

Save PublicKey to storage in PKCS1.

func (*RsaKeys) SavePublicKeyPKIX

func (r *RsaKeys) SavePublicKeyPKIX() (err error)

Save PublicKey to storage in PKIX format.

func (*RsaKeys) SetPrivateKey

func (r *RsaKeys) SetPrivateKey(privateKey []byte) (err error)

Parses a PEM encoded private key.

func (*RsaKeys) SetPrivateKeyString

func (r *RsaKeys) SetPrivateKeyString(privateKey string) (err error)

Set the private key string.

func (*RsaKeys) SetPublicKey

func (r *RsaKeys) SetPublicKey(publicKey []byte) (err error)

Parses a PEM encoded public key.

func (*RsaKeys) SetPublicKeyString

func (r *RsaKeys) SetPublicKeyString(publicKey string) (err error)

Set the public key string.

type RsaSign

type RsaSign struct {
	Hash      crypto.Hash
	Signature []byte
	Payload   []byte
}

A place for create or load signature ;

func (*RsaSign) FromBase64

func (r *RsaSign) FromBase64(signature string) (err error)

Get signature as base64.

func (*RsaSign) ToBase64

func (r *RsaSign) ToBase64() string

Get signature to base64.

type SagaLogger

type SagaLogger struct {
	StateDescription map[saga.State]string
}

func (*SagaLogger) Log

func (sl *SagaLogger) Log(ctx context.Context, tx saga.Transaction) error

type SagaState

type SagaState struct {
	ProcessState saga.State
}

func (*SagaState) State

func (t *SagaState) State() saga.State

type TypeConverter

type TypeConverter struct {
	SrcType interface{}
	DstType interface{}
	Fn      func(src interface{}) (dst interface{}, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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