ice

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppEnv

type AppEnv interface {
	IsProd() bool // production
	IsRC() bool   // release candidate
	IsBox() bool  // sandbox
	IsStg() bool  // staging
	IsDev() bool  // development

	GetName() string
	IsRP() bool // release candidate + production
}

type Box

type Box interface {
	Set(key, subKey string, val any)
	GetValue(key, subKey string) any
	GetSub(key string) map[string]any
}

type Conf

type Conf interface {
	SetZxEnvName(name string) Conf
	SetTimezone(timezone string) Conf
	SetClogAddress(address string, svcName string, svcVersion string) Conf
	SetClogRetryMaxDuration(duration time.Duration) Conf
	SetInternalBaseUrls(urls []string) Conf

	// address "-" means no engine, so all the feature will success every time, used when on development
	SetTxLockEngine(address string, dvalTimeout time.Duration, dvalTryFor *time.Duration) Conf

	Commit()
}

type Conv

type Conv interface{}

type ConvTime

type ConvTime interface {
	ToStrFull(val time.Time) string
	ToStrDT(val time.Time) string

	ToTimeFull(val string) (*time.Time, error)
	ToTimeDT(val string) (*time.Time, error)
}

type Crypto

type Crypto interface {
	AesEcbEncrypt(key, value string) (string, error)
	AesEcbRawEncrypt(key, value string) ([]byte, error)
	AesEcbDecrypt(key, value string) (string, error)
	AesEcbRawDecrypt(key string, value []byte) ([]byte, error)
	Md5(val string) string
	Sha256(val string) string
	Sha512(val string) string
}

type Db

type Db interface {
	Postgres(conf mol.DbConnection) DbPostgresInstance
	PostgresRW(readConf mol.DbConnection, writeConf mol.DbConnection) DbPostgresInstance
}

type DbInstance

type DbInstance interface {
	Ping() (string, error)
	PingRead() (string, error)
	NewTransaction() (DbTx, error)

	Select(out any, query string, args ...any) (*mol.DbExecReport, error)
	SelectR2(out any, query string, args []any, check *func() bool) (*mol.DbExecReport, error)
	Execute(query string, args ...any) (*mol.DbExecReport, error)
	ExecuteRID(query string, args ...any) (*int64, *mol.DbExecReport, error)

	TxSelect(tx DbTx, out any, query string, args ...any) (*mol.DbExecReport, error)
	TxExecute(tx DbTx, query string, args ...any) (*mol.DbExecReport, error)
	TxExecuteRID(tx DbTx, query string, args ...any) (*int64, *mol.DbExecReport, error)
}

type DbPostgresInstance

type DbPostgresInstance interface {
	DbInstance
}

type DbTx

type DbTx interface {
	Commit() error
	Rollback() error
}

type GM

type GM interface {
	SetBox(box Box) GM
	SetConf(conf Conf) GM
	SetConv(conv Conv, tm ConvTime) GM
	SetCrypto(crypto Crypto) GM
	SetDb(db Db) GM
	SetHttp(http Http) GM
	SetJson(json Json) GM
	SetLock(lock Lock) GM
	SetNet(net Net) GM
	SetTest(test Test) GM
	SetUtil(util Util, env UtilEnv) GM
}

type Http

type Http interface {
	Get(clog clog.Instance, url string) HttpBuilder
	Post(clog clog.Instance, url string) HttpBuilder
	Put(clog clog.Instance, url string) HttpBuilder
	Patch(clog clog.Instance, url string) HttpBuilder
	Delete(clog clog.Instance, url string) HttpBuilder
}

type HttpBuilder

type HttpBuilder interface {
	SetTimeout(duration time.Duration) HttpBuilder

	// disable security check (https)
	InsecureSkipVerify(skip ...bool) HttpBuilder

	// Example:
	//	SetRetryCondition(func(resp ice.HttpResponse) bool {
	//		return resp.Code() == http.StatusTooManyRequests
	//	})
	SetRetryCondition(condition func(resp HttpResponse, count int) bool) HttpBuilder
	SetMaxRetry(max int) HttpBuilder

	EnableTrace(enable ...bool) HttpBuilder
	SetHeader(args map[string]string) HttpBuilder

	// Example:
	//  SetJsonHeader("1.0", map[string]string{
	// 		"Authorization": "Bearer xyz",
	//  })
	// string "1.0" it will convert to "X-Version",
	// then map[string]string will added to header value
	SetJsonHeader(opt ...any) HttpBuilder

	// Examples:
	//
	//	Get(".../users/{userId}/{subAccountId}/details").
	//	SetPathParams(map[string]any{
	//		"userId": "sample@sample.com",
	//		"subAccountId": "100002",
	//	})
	SetPathParam(args map[string]string) HttpBuilder

	SetQueryParam(args map[string]string) HttpBuilder
	SetFormData(args map[string]string) HttpBuilder

	// Examples:
	//
	//	SetBody(User{
	//		Username: "jeeva@myjeeva.com",
	//		Password: "welcome2resty",
	//	})
	//
	//	SetBody(map[string]any{
	//		"username": "jeeva@myjeeva.com",
	//		"password": "welcome2resty",
	//		"address": &Address{
	//			City: "My City",
	//			ZipCode: 00000,
	//		},
	//	})
	//
	//	SetBody(`{
	//		"username": "jeeva@getrightcare.com",
	//		"password": "admin"
	//	}`)
	//
	//	SetBody([]byte("This is my raw request, sent as-is"))
	//
	SetBody(value any) HttpBuilder

	// Examples:
	// profileImgBytes, _ := os.ReadFile("/andy/test-img.png")
	// notesBytes, _ := os.ReadFile("/andy/text-file.txt")
	//
	//	AddFileReader("profile_img", "my-profile-img.png", bytes.NewReader(profileImgBytes)).
	//	AddFileReader("notes", "user-notes.txt", bytes.NewReader(notesBytes))
	AddFileReader(param, fileName string, reader io.Reader) HttpBuilder

	// Examples:
	//
	//	SetFiles(map[string]string{
	//		"file1": "/andy/invoice.pdf",
	//		"file2": "/andy/detail.pdf",
	//		"file3": "/andy/summary.pdf",
	//	})
	SetFiles(files map[string]string) HttpBuilder

	Call() (data []byte, code int, err error)
}

type HttpResponse

type HttpResponse interface {
	Body() []byte
	IsError() bool
	IsSuccess() bool
	Error() error
	Code() int

	IsTimeout() bool
	IsConnectionReset() bool
}

type Json

type Json interface {
	Marshal(obj any) ([]byte, error)
	Unmarshal(data []byte, out any) error
	Encode(obj any) (string, error)
	Decode(jsonStr string, out any) error
	MapToJson(maps map[string]any) (string, error)
}

type Lock added in v1.0.2

type Lock interface {
	NewOpt() LockOpt

	// code
	// -1:
	//  0: have an error
	//  1: locked
	Tx(id string, opt ...LockOpt) (LockInstance, error)
}

type LockInstance added in v1.0.2

type LockInstance interface {
	Release()
	IsLocked() (bool, error)
	Extend(duration time.Duration) error
}

type LockOpt added in v1.0.2

type LockOpt interface {
	SetTimeout(duration time.Duration) LockOpt
	TryFor(duration time.Duration) LockOpt
	SetPrefix(prefix string) LockOpt
}

type Net

type Net interface {
	IsPortUsed(port int, host ...string) bool
	GrpcConnection(address string, opt ...mol.NetOpt) (grpc.ClientConnInterface, error)
}

type Test

type Test interface {
	Start(t *testing.T, fn func(t *testing.T))
	Printf(t *testing.T, format string, args ...any)
}

type Util

type Util interface {
	IsEmailValid(email string, verifyDomain ...bool) bool
	Timenow(timezone ...string) time.Time
	ConcurrentProcess(total, max int, fn func(index int))

	LiteUID() string
	UID(addition ...int) string
	GetAlphabet(isUpper ...bool) string
	GetNumeric() string
	GetRandom(length int, value string) string
	DecodeUID(uid string, addition ...int) (rawId string, randId string, err error)
	ReplaceAll(value *string, replaceValue string, replaceKey ...string) *string

	ReadTextFile(filePath string) ([]string, error)
	LoadEnv(filePath ...string) error
	GetExecDir() (string, error)
	GetExecPathFunc(skip ...int) (string, string)
	SingleExec(fn func())

	PanicCatcher(fn func()) (err error)
	ReflectionGet(obj any, fieldName string) (any, error)
	ReflectionSet(obj any, bind map[string]any) error
	StackTrace(skip ...int) string
}

type UtilEnv

type UtilEnv interface {
	GetAppEnv(key string) AppEnv
	GetString(key string, dval ...string) string
	GetInt(key string, dval ...int) int
	GetInt32(key string, dval ...int32) int32
	GetInt64(key string, dval ...int64) int64
	GetBool(key string, dval ...bool) bool

	GetStringSlice(key string, separator string, dval ...[]string) []string
	GetDurationMs(key string, dval ...time.Duration) time.Duration
}

Jump to

Keyboard shortcuts

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