Documentation
¶
Index ¶
- Constants
- func BoolRef(v bool) *bool
- func CurrentLocalTime() time.Time
- func CurrentUTCTime() time.Time
- func CurrentUTCTimeRef() *time.Time
- func CurrentUnixTimestamp() int64
- func Decrypt(ciphertext string, key string) (plaintext string, err error)
- func Encrypt(plaintext string, key string) (ciphertext string, err error)
- func GetBasic(ctx context.Context, key string) (value interface{})
- func GetStatsD(ctx context.Context) (statsD *statsd.Client)
- func GetString(ctx context.Context, key ContextKey) (value string)
- func IDToRef(id uint, prefix string, length int, refChars, refPaddingChars string) (string, error)
- func Int32Ref(v int32) *int32
- func Int64Ref(v int64) *int64
- func RefToID(ref, prefix string, refChars, refPaddingChars string) (uint64, error)
- func SetBasics(parent context.Context, basics Basics) context.Context
- func SetExtras(parent context.Context, extras Extras) context.Context
- func SetStatsD(parent context.Context, statsD *statsd.Client) context.Context
- func StrRef(v string) *string
- func String2Uint(s string, chars, paddingChars string) (n uint64, err error)
- func TimeChanged(new *time.Time, base *time.Time) (bool, *time.Time)
- func TimeRef(v time.Time) *time.Time
- func Uint2String(number uint64, chars, paddingChars string, length int) (s string, err error)
- func Uint32Ref(v uint32) *uint32
- func UintRef(v uint) *uint
- func ValidateCardNumber(number string) bool
- type Basics
- type ContextKey
- type DMutex
- type Date
- type DistributedLocker
- type Extras
- type UnLocker
Constants ¶
const ( AcceptLanguage = "Accept-Language" Authorization = "Authorization" ContentType = "Content-Type" UserAgent = "User-Agent" APIKey = "ApiKey" BearerPrefix = "Bearer " ApplicationJSON = "application/json" TextXML = "text/xml" RequestIDHeader = "X-Request-ID" ClientCodeParam = "clientCode" MaxRequestIDLength = 64 AESKeyLength = 32 BINLength = 6 )
common constants
const ( DateFormat = "02 Jan 2006" DayOfWeekFormat = "Mon" DateTimeFormat = "02 Jan 2006, 03:04 PM MST" YearFormat = "2006" )
date time string formats
Variables ¶
This section is empty.
Functions ¶
func CurrentLocalTime ¶
CurrentLocalTime returns current date time in local timezone
func CurrentUTCTime ¶
CurrentUTCTime returns current date time in UTC
func CurrentUTCTimeRef ¶
CurrentUTCTimeRef returns current date time reference in UTC
func CurrentUnixTimestamp ¶
func CurrentUnixTimestamp() int64
CurrentUnixTimestamp returns current Unix timestamp (seconds)
func GetString ¶
func GetString(ctx context.Context, key ContextKey) (value string)
GetString gets string from a context by ContextKey
func SetBasics ¶ added in v0.1.3
SetBasics returns a copy of parent context with basics added into it
func String2Uint ¶ added in v0.1.2
String2Uint is the revert of Uint2String
It returns negative result in 2 cases: - s contains character not exist in chars - the result is bigger than max int64 (integer overflow happen)
func TimeChanged ¶
TimeChanged check if new time changed from the base, return the changed flag and time value
func Uint2String ¶ added in v0.1.2
Uint2String converts a number to a string using characters from chars.
Validation:
- `length` must > 0
- length of `chars` must >= 10
- `paddingChars` must not be empty
- `chars` & `paddingChars` must not overlap
If length of the result < required length, the result will be left padded with random characters from `paddingChars`.
func ValidateCardNumber ¶
ValidateCardNumber will check the credit card's number against the Luhn algorithm
Types ¶
type Basics ¶ added in v0.1.3
type Basics map[string]interface{}
Basics are basics information to be added into context
type DMutex ¶
type DMutex struct {
// contains filtered or unexported fields
}
DMutex a simple distributed mutex for lock with keys
type Date ¶
Date : custom date in format yyyy-MM-dd
func (Date) MarshalJSON ¶
MarshalJSON marshall Date into JSON
func (*Date) UnmarshalJSON ¶
UnmarshalJSON Parses the json string in the Date
type DistributedLocker ¶
DistributedLocker a distributed lock type