util

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XHasuraRole       = "x-hasura-role"
	XHasuraUserID     = "x-hasura-user-id"
	XHasuraUserEmail  = "x-hasura-user-email"
	XHasuraIsSAMLUser = "x-hasura-user-saml"
	// Returned only for metrics role
	XHasuraAllowedProjectIDs        = "x-hasura-allowed-project-ids"
	XHasuraAllowedMetricsProjectIDs = "x-hasura-allowed-metrics-project-Ids"
	XHasuraAdminProjectIDs          = "x-hasura-admin-project-ids"
	// Returned for licensing public role
	Authorization     = "Authorization"
	SUBSCRIPTION_DATE = 1
)

Variables

This section is empty.

Functions

func BeginningLastMonth

func BeginningLastMonth() time.Time

func BeginningNextMonth

func BeginningNextMonth() time.Time

func BeginningOf28thDayOfMonth

func BeginningOf28thDayOfMonth(month, year int) time.Time

func BeginningOfInputMonth

func BeginningOfInputMonth(month, year int) time.Time

func BeginningOfLastMonth

func BeginningOfLastMonth() time.Time

func BeginningOfMonth

func BeginningOfMonth() time.Time

func BeginningOfNextMonth

func BeginningOfNextMonth() time.Time

BeginningOfNextMonth returns the absolute beginning of the next month

func EndOfInputMonth

func EndOfInputMonth(month, year int) time.Time

func EndOfLastMonth

func EndOfLastMonth() time.Time

func EndOfMonth

func EndOfMonth() time.Time

func Float64Ptr

func Float64Ptr(input float64) *float64

Float64Ptr returns pointer of the float64 input

func GetBeginningOfNextMonth

func GetBeginningOfNextMonth() time.Time

GetBeginningOfNextMonth returns the date at which the new billing cycle kicks in

func GetBeginningOfThisMonth

func GetBeginningOfThisMonth() time.Time

func GetCurrentMonthString

func GetCurrentMonthString() string

func GetEnv

func GetEnv(key string, defaultValue string) string

func GetNextMonthString

func GetNextMonthString() string

func GetTime

func GetTime() *string

func GetTimeSinceStartOfMonth

func GetTimeSinceStartOfMonth() string

GetTimeSinceStartOfMonth returns the string of time since the start of the month in the same format as `time.Since`

func IsPtrNil

func IsPtrNil(v any) bool

IsPtrNil returns true if input to function is nil or nil pointer

func LogError

func LogError(deploymentId uuid.UUID, message string, err error)

func LogFuncExecTime

func LogFuncExecTime(log zerolog.Logger, funcName string, callbacks ...func(startTime time.Time)) func()

LogFuncExecTime logs the execution time of a function and can (optionally) execute callback functions. Example of a potential callback is to raise an alert if the execution time is high. This is best suited to be called as a deferred function at the start of the target function. For usage example, refer `CheckDataUsageComponents` in the `api` service.

func LogInfo

func LogInfo(deploymentId uuid.UUID, message string)

func MapStringToUUID

func MapStringToUUID(arr []string) ([]uuid.UUID, error)

MapStringToUUID parse array strings to uuids

func NoOfDaysInLastMonth

func NoOfDaysInLastMonth() int

func NoOfDaysInMonth

func NoOfDaysInMonth() int

Returns no of days in a month

func NoOp

func NoOp()

func PostgresArrayToStrings

func PostgresArrayToStrings(s string) ([]string, error)

PostgresArrayToStrings convert postgres array to string array

func SetDate

func SetDate(t time.Time, day int) time.Time

func SetDateAndHour

func SetDateAndHour(t time.Time, day int, hour int) time.Time

func TimeDiff

func TimeDiff(a, b time.Time) (year, month, day, hour, min, sec int)

TimeDiff calculates the absolute difference between 2 time instances in years, months, days, hours, minutes and seconds.

For details, see https://stackoverflow.com/a/36531443/1705598

func TimeDiffString

func TimeDiffString(a, b time.Time) (timeString string)

TimeDiffString returns a string similar to the Duration type. It runs the TimeDiff function internally. Please note that this only works for returning correct strings for days, hours, minutes and seconds. In case you're using this function for Prometheus queries that stretch over years or months, please do not use this function since Prometheus supports the following durations: milliseconds, seconds, minutes, hours, weeks and years. With weeks being involved in between, due to the nature of TimeDiff, this function will not provide the correct result.

Examples:

TimeDiffString(time.Now(), time.Now().Add(-12 * time.Minute)) // 12m
TimeDiffString(time.Now().Add(-365 * 24 * time.Hour), time.Now()) // -8760h0m0s

func TimePtr

func TimePtr(input time.Time) *time.Time

TimePtr returns pointer of the input time

func ToAnyMap

func ToAnyMap[K comparable, E any](input map[K]E) map[K]any

ToAnyMap a generic function to convert the input map to any map

Types

type JsonList

type JsonList []string

JsonList stores strings representing json

func (*JsonList) Add

func (jl *JsonList) Add(values ...string)

Add append new value or skip if it's existing

func (JsonList) Compact

func (jl JsonList) Compact() JsonList

Compact returns a copy of the JSON list with empty elements removed

func (JsonList) IsEmpty

func (jl JsonList) IsEmpty() bool

IsEmpty check if the array is empty

func (JsonList) ToJson

func (jl JsonList) ToJson() []byte

ToJson serializes the JSON List into a valid JSON array. Elements are not marshalled, because they are json already

func (JsonList) ToJsonSingleElementOrArray

func (jl JsonList) ToJsonSingleElementOrArray() []byte

ToJsonSingleElementOrArray serializes a list containing a single element into that element's JSON; and into an array if it contains multiple elements.

type StringList

type StringList []string

StringList stores string values

func (*StringList) Add

func (sl *StringList) Add(values ...string)

Add append new value or skip if it's existing

func (StringList) Compact

func (sl StringList) Compact() StringList

Compact returns a copy of the string list with empty elements removed

func (StringList) IsEmpty

func (sl StringList) IsEmpty() bool

IsEmpty check if the array is empty

func (StringList) String

func (sl StringList) String() string

String implements the Stringer interface

func (StringList) ToJson

func (sl StringList) ToJson() []byte

ToJson serializes the StringList into Json

func (StringList) UniqueString

func (sl StringList) UniqueString() string

UniqueString creates a string of comma separated unique values sorted alphabetically

type StringMap

type StringMap map[string]string

StringMap wrapper for string map

func (StringMap) Get

func (sm StringMap) Get(key string) string

Get get string value from map by key

Jump to

Keyboard shortcuts

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