candihelper

package
v1.7.11 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 14 Imported by: 9

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

	// 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"
	// 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"
)

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 BuildRedisPubSubKeyTopic

func BuildRedisPubSubKeyTopic(handlerName string, message interface{}) string

BuildRedisPubSubKeyTopic helper

func CronJobKeyToString

func CronJobKeyToString(jobName, args, interval string) string

CronJobKeyToString helper

Allowed interval:

* standard time duration string, example: 2s, 10m

* custom start time and repeat duration, example:

  • 23:00@daily, will repeated at 23:00 every day
  • 23:00@weekly, will repeated at 23:00 every week
  • 23:00@10s, will repeated at 23:00 and next repeat every 10 seconds

func GetFuncName

func GetFuncName(fn interface{}) string

GetFuncName get function name in string

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 ParseCronJobKey

func ParseCronJobKey(str string) (jobName, args, interval string)

ParseCronJobKey helper

func ParseFromQueryParam

func ParseFromQueryParam(query url.Values, target interface{}) (err error)

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

func ParseRedisPubSubKeyTopic

func ParseRedisPubSubKeyTopic(str string) (handlerName, messageData string)

ParseRedisPubSubKeyTopic helper

func ParseToQueryParam

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

ParseToQueryParam parse struct data to query param

func PtrToBool

func PtrToBool(ptr *bool) (b bool)

PtrToBool helper

func PtrToFloat

func PtrToFloat(ptr *float64) (f float64)

PtrToFloat helper

func PtrToInt

func PtrToInt(ptr *int) (i int)

PtrToInt helper

func PtrToString

func PtrToString(ptr *string) (s string)

PtrToString helper

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

func ToFloatPtr

func ToFloatPtr(f float64) *float64

ToFloatPtr helper

func ToIntPtr

func ToIntPtr(i int) *int

ToIntPtr helper

func ToStringPtr

func ToStringPtr(str string) *string

ToStringPtr helper

func ToUTC

func ToUTC(t time.Time) time.Time

ToUTC convert only location to UTC

Types

type CronJobKey

type CronJobKey struct {
	JobName  string `json:"jobName"`
	Args     string `json:"args"`
	Interval string `json:"interval"`
}

CronJobKey model

func (CronJobKey) String

func (c CronJobKey) String() string

String implement stringer

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 RedisMessage

type RedisMessage struct {
	HandlerName string `json:"h"`
	Message     string `json:"message"`
}

RedisMessage model for redis subscriber key

type TryCatch

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

TryCatch model

func (TryCatch) Do

func (t TryCatch) Do()

Do run TryCatch

Jump to

Keyboard shortcuts

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