common

package module
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	ClientCodeParam    = "clientCode"
	MaxRequestIDLength = 64
	BINLength          = 6
)

common constants

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

func CurrentLocalTime() time.Time

CurrentLocalTime returns current date time in local timezone

func CurrentUTCTime

func CurrentUTCTime() time.Time

CurrentUTCTime returns current date time in UTC

func CurrentUTCTimeRef

func CurrentUTCTimeRef() *time.Time

CurrentUTCTimeRef returns current date time reference in UTC

func CurrentUnixTimestamp

func CurrentUnixTimestamp() int64

CurrentUnixTimestamp returns current Unix timestamp (seconds)

func GenerateCardNumberFromBin added in v0.1.14

func GenerateCardNumberFromBin(bin string, cardNumberLen int) string

GenerateCardNumberFromBin will generate credit card number based on bin number and the card number length

func GetBasic added in v0.1.3

func GetBasic(ctx context.Context, key string) (value interface{})

GetBasic gets basic from the context with key

func GetExtra added in v0.1.6

func GetExtra(ctx context.Context, key string) (value interface{})

GetExtra gets Extra from the context with key

func GetStatsD

func GetStatsD(ctx context.Context) (statsD *statsd.Client)

GetStatsD gets statsD client from the context if any

func GetString

func GetString(ctx context.Context, key ContextKey) (value string)

GetString gets string from a context by ContextKey

func SetBasic added in v0.1.4

func SetBasic(parent context.Context, key string, value interface{}) context.Context

SetBasic returns a copy of parent context with basic key value added into it

func SetBasics added in v0.1.3

func SetBasics(parent context.Context, basics Basics) context.Context

SetBasics returns a copy of parent context with basics added into it

func SetExtra added in v0.1.6

func SetExtra(parent context.Context, key string, value interface{}) context.Context

SetExtra returns a copy of parent context with Extra key value added into it

func SetExtras

func SetExtras(parent context.Context, extras Extras) context.Context

SetExtras returns a copy of parent context with extras added into it

func SetStatsD

func SetStatsD(parent context.Context, statsD *statsd.Client) context.Context

SetStatsD returns a copy of parent context with statsD client added into it

func TimeChanged

func TimeChanged(new *time.Time, base *time.Time) (bool, *time.Time)

TimeChanged check if new time changed from the base, return the changed flag and time value

func ValidateCardNumber

func ValidateCardNumber(number string) bool

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

func GetBasics added in v0.1.3

func GetBasics(ctx context.Context) (value Basics)

GetBasics gets basics from the context if any

type ContextKey

type ContextKey string

ContextKey is key to be used to store values to context

type DMutex

type DMutex struct {
	// contains filtered or unexported fields
}

DMutex a simple distributed mutex for lock with keys

func (*DMutex) Lock

func (dm *DMutex) Lock(key string) (UnLocker, error)

Lock the specific key

type Date

type Date time.Time

Date : custom date in format yyyy-MM-dd

func (Date) Before

func (d Date) Before(other Date) bool

Before checks if the date is before the other date

func (Date) Equal

func (d Date) Equal(other time.Time) bool

Equal check if date is present the same time instant with other

func (Date) IsZero

func (d Date) IsZero() bool

IsZero check if date is present zero time instance

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON marshall Date into JSON

func (Date) String

func (d Date) String() string

String returns the time in the custom format

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON Parses the json string in the Date

type DistributedLocker

type DistributedLocker interface {
	// Lock the specific key
	Lock(key string) (UnLocker, error)
}

DistributedLocker a distributed lock type

type Extras

type Extras map[string]interface{}

Extras are extra information to be added into context

func GetExtras

func GetExtras(ctx context.Context) (value Extras)

GetExtras gets extras from the context if any

type UnLocker

type UnLocker func()

UnLocker unlock function

Jump to

Keyboard shortcuts

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