candihelper

package
v1.17.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 20 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// TimeZoneAsia constanta
	TimeZoneAsia = "Asia/Jakarta"
	// TokenClaimKey const
	TokenClaimKey = "tokenClaim"

	// TimeFormatLogger const
	TimeFormatLogger = "2006/01/02 15:04:05"

	// V1 const
	V1 = "/v1"
	// V2 const
	V2 = "/v2"

	// Byte ...
	Byte uint64 = 1
	// KByte ...
	KByte = Byte * 1024
	// MByte ...
	MByte = KByte * 1024
	// GByte ...
	GByte = MByte * 1024
	// TByte ...
	TByte = GByte * 1024

	// WORKDIR const for workdir environment
	WORKDIR = "WORKDIR"
	// RepositorySQL unit of work for sql repository
	RepositorySQL = "repositorySQL"
	// RepositoryMongo unit of work for mongodb repository
	RepositoryMongo = "repositoryMongo"

	// HeaderDisableTrace const
	HeaderDisableTrace = "X-Disable-Trace"
	// HeaderXForwardedFor const
	HeaderXForwardedFor = "X-Forwarded-For"
	// HeaderXRealIP const
	HeaderXRealIP = "X-Real-IP"
	// HeaderContentType const
	HeaderContentType = "Content-Type"
	// HeaderAuthorization const
	HeaderAuthorization = "Authorization"
	// HeaderCacheControl header const
	HeaderCacheControl = "Cache-Control"
	// HeaderExpires header const
	HeaderExpires = "Expires"
	// HeaderLastModified header const
	HeaderLastModified = "Last-Modified"
	// HeaderIfModifiedSince header const
	HeaderIfModifiedSince = "If-Modified-Since"
	// HeaderMIMEApplicationJSON const
	HeaderMIMEApplicationJSON = "application/json"
	// HeaderMIMEApplicationXML const
	HeaderMIMEApplicationXML = "application/xml"
	// HeaderMIMEApplicationForm const
	HeaderMIMEApplicationForm = "application/x-www-form-urlencoded"
	// HeaderMIMEMultipartForm const
	HeaderMIMEMultipartForm = "multipart/form-data"
	// HeaderMIMEOctetStream const
	HeaderMIMEOctetStream = "application/octet-stream"

	// DateFormatMonday date format
	DateFormatMonday = "Monday"
	// DateFormatYYYYMM date format
	DateFormatYYYYMM = "2006-01"
	// DateFormatYYYYMMDD date format
	DateFormatYYYYMMDD = "2006-01-02"
	// DateFormatYYYYMMDDHHmmss date format
	DateFormatYYYYMMDDHHmmss = "2006-01-02 15:04:05"
	// DateFormatYYYYMMDDClean date format
	DateFormatYYYYMMDDClean = "20060102"
	// DateFormatHHmmss date format
	DateFormatHHmm = "15:04"
	// DateFormatDDMMYYYY date format
	DateFormatDDMMYYYY = "02-01-2006"
)
View Source
const (
	// OneDay const
	OneDay = 24 * time.Hour
	// OneWeek const
	OneWeek = 7 * OneDay
	// OneMonth const
	OneMonth = 30 * OneDay
	// OneYear const
	OneYear = 12 * OneMonth

	// Daily const
	Daily = "daily"
	// Weekly const
	Weekly = "weekly"
	// Monthly const
	Monthly = "monthly"
	// Yearly const
	Yearly = "yearly"
)

Variables

View Source
var (
	// Green color
	Green = []byte{27, 91, 57, 55, 59, 52, 50, 109}
	// White color
	White = []byte{27, 91, 57, 48, 59, 52, 55, 109}
	// Yellow color
	Yellow = []byte{27, 91, 57, 48, 59, 52, 51, 109}
	// Red color
	Red = []byte{27, 91, 57, 55, 59, 52, 49, 109}
	// Blue color
	Blue = []byte{27, 91, 57, 55, 59, 52, 52, 109}
	// Magenta color
	Magenta = []byte{27, 91, 57, 55, 59, 52, 53, 109}
	// Cyan color
	Cyan = []byte{27, 91, 57, 55, 59, 52, 54, 109}
	// Reset color
	Reset = []byte{27, 91, 48, 109}

	// AsiaJakartaLocalTime location
	AsiaJakartaLocalTime *time.Location
)

Functions

func ByteToString added in v1.14.0

func ByteToString(b []byte) string

ByteToString helper with zero allocation

func ElementInSlice added in v1.17.0

func ElementInSlice[T comparable](el T, list []T) bool

ElementInSlice check element is exist in slice

func GenerateHMAC added in v1.9.0

func GenerateHMAC(salt, str string) string

GenerateHMAC generate random string

func GenerateSHA1 added in v1.9.0

func GenerateSHA1(input []byte) string

GenerateSHA1 generate SHA1

func GetFuncName

func GetFuncName(fn interface{}) string

GetFuncName get function name in string

func GetRuntimeStackLine added in v1.10.4

func GetRuntimeStackLine() string

GetRuntimeStackLine helper

func IsExistInMap added in v1.16.2

func IsExistInMap[T any, K comparable](m map[K]T, key K) bool

IsExistInMap check key is exist in map

func LoadAllFile

func LoadAllFile(path, formatFile string) []byte

LoadAllFile from path

func MaskingPasswordURL

func MaskingPasswordURL(stringURL string) string

MaskingPasswordURL for hide plain text password from given URL format

func MustParseEnv

func MustParseEnv(target interface{})

MustParseEnv must parse env to struct, panic if env from target struct tag is not found

func ParseDurationExpression added in v1.13.0

func ParseDurationExpression(t string) (duration, nextDuration time.Duration, err error)

ParseDurationExpression with input format HH:mm:ss

func ParseFromQueryParam

func ParseFromQueryParam(query URLQueryGetter, target interface{}) (err error)

ParseFromQueryParam parse url query string to struct target (with multiple data type in struct field), target must in pointer

func ParseTimeToString added in v1.14.8

func ParseTimeToString(date time.Time, format string) (res string)

ParseTimeToString helper, return empty string if zero time

func ParseToQueryParam

func ParseToQueryParam(source interface{}) (s string)

ParseToQueryParam parse struct data to query param

func PrintJSON added in v1.8.14

func PrintJSON(data interface{})

PrintJSON for show data in pretty JSON with stack trace

func PtrToBool

func PtrToBool(ptr *bool) (b bool)

PtrToBool helper

func PtrToFloat

func PtrToFloat(ptr *float64) (f float64)

PtrToFloat helper

func PtrToFloat32 added in v1.10.5

func PtrToFloat32(ptr *float32) (f float32)

PtrToFloat32 helper

func PtrToInt

func PtrToInt(ptr *int) (i int)

PtrToInt helper

func PtrToString

func PtrToString(ptr *string) (s string)

PtrToString helper

func PtrToTime added in v1.10.5

func PtrToTime(ptr *time.Time) (t time.Time)

PtrToTime helper

func ReflectTypeUnwrapPtr added in v1.17.3

func ReflectTypeUnwrapPtr(f reflect.Type) reflect.Type

func ReflectValueUnwrapPtr added in v1.17.3

func ReflectValueUnwrapPtr(f reflect.Value) reflect.Value

func StreamAllBatch added in v1.14.11

func StreamAllBatch[T any, F FilterStreamer](ctx context.Context, totalData int, filter F, fetchAllFunc func(context.Context, F) ([]T, error), handleFunc func(idx int, data *T) error) error

StreamAllBatch helper func for stream data

func StreamAllBatchDynamic added in v1.15.9

func StreamAllBatchDynamic[T any, F FilterStreamer](ctx context.Context, filter F, fetchAllFunc func(context.Context, F) ([]T, error), handleFunc func(idx int, data *T) error) error

StreamAllBatchDynamic helper func for stream data with dynamic source changes

func StringGreen

func StringGreen(str string) string

StringGreen func

func StringInSlice

func StringInSlice(str string, list []string) bool

StringInSlice function for checking whether string in slice str string searched string list []string slice

func StringToByte added in v1.14.0

func StringToByte(s string) (b []byte)

StringToByte helper with zero allocation

func StringYellow

func StringYellow(str string) string

StringYellow func

func TimeRemoveNanosecond

func TimeRemoveNanosecond(t time.Time) time.Time

TimeRemoveNanosecond ...

func ToAsiaJakartaTime

func ToAsiaJakartaTime(t time.Time) time.Time

ToAsiaJakartaTime convert only time location to AsiaJakarta local time

func ToBoolPtr

func ToBoolPtr(b bool) *bool

ToBoolPtr helper

func ToBytes

func ToBytes(i interface{}) (b []byte)

ToBytes convert all types to json bytes

func ToCamelCase added in v1.9.0

func ToCamelCase(str string) string

ToCamelCase helper

func ToDelimited added in v1.9.0

func ToDelimited(s string, delimiter uint8) string

ToDelimited helper, can use to snake_case or kebab-case

func ToFloat32Ptr added in v1.10.5

func ToFloat32Ptr(f float32) *float32

ToFloat32Ptr helper

func ToFloatPtr

func ToFloatPtr(f float64) *float64

ToFloatPtr helper

func ToInt added in v1.11.22

func ToInt(val interface{}) (i int)

ToInt helper

func ToIntPtr

func ToIntPtr(i int) *int

ToIntPtr helper

func ToKeyMapSlice added in v1.16.2

func ToKeyMapSlice[T any, K comparable](mp map[K]T) (list []K)

ToKeyMapSlice transform key of map to slice

func ToMap added in v1.16.2

func ToMap[T any, K comparable](list []T, keyGetter func(T) K) map[K]T

ToMap transform slice to map

func ToString added in v1.11.22

func ToString(val interface{}) (str string)

ToString helper

func ToStringPtr

func ToStringPtr(str string) *string

ToStringPtr helper

func ToTimePtr added in v1.10.5

func ToTimePtr(t time.Time) *time.Time

ToTimePtr helper

func ToUTC

func ToUTC(t time.Time) time.Time

ToUTC convert only location to UTC

func TransformSizeToByte added in v1.14.11

func TransformSizeToByte(size uint64) string

TransformSizeToByte helper

func UnwrapPtr added in v1.16.1

func UnwrapPtr[T any](t *T) (res T)

UnwrapPtr take value from pointer

func WrapPtr added in v1.16.1

func WrapPtr[T any](t T) *T

WrapPtr set pointer from value

Types

type FilterStreamer added in v1.14.11

type FilterStreamer interface {
	GetPage() int
	IncrPage()
	GetLimit() int
}

FilterStreamer abstract interface

type MultiError

type MultiError interface {
	Append(key string, err error) MultiError
	HasError() bool
	IsNil() bool
	Clear()
	ToMap() map[string]string
	Merge(MultiError) MultiError
	Error() string
}

MultiError abstract interface

func NewMultiError

func NewMultiError() MultiError

NewMultiError constructor

type TryCatch

type TryCatch struct {
	Try   func()
	Catch func(error)
}

TryCatch model

func (TryCatch) Do

func (t TryCatch) Do()

Do run TryCatch

type URLQueryGetter added in v1.13.14

type URLQueryGetter interface {
	Get(key string) string
}

URLQueryGetter abstraction

Jump to

Keyboard shortcuts

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