stdlib

package module
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 15 Imported by: 18

README

txsvc/stdlib

My "standard library" of go functions I always use in all kinds of projects and repos.

Documentation

Index

Constants

View Source
const (
	LOG_LEVEL = "LOG_LEVEL"
)

Variables

This section is empty.

Functions

func Checksum

func Checksum(a string) string

Checksum creates a unique CRC32 checksum from a string

func ElapsedTimeSince

func ElapsedTimeSince(t time.Time) int64

ElapsedTimeSince returns the difference between t and now.

func Exists

func Exists(env string) bool

Exists verifies that the environment variable 'env' is defined and returns a non-empty value.

func Fingerprint

func Fingerprint(a string) string

Fingerprint creates a unique ID (MD5) from a string

func GetBool added in v2.5.0

func GetBool(env string, def bool) bool

GetBool returns the environment variable ENV['env'] as boolean or def if 'env' is not set.

func GetInt

func GetInt(env string, def int64) int64

GetInt returns the environment variable ENV['env'] as an int64 or def if 'env' is not set.

func GetString

func GetString(env, def string) string

GetString returns the environment variable ENV['env'] or def if 'env' is not set. Note: def is only returned if the 'env' is not set, i.e. an EMPTY 'env' is still returned !

func IncT

func IncT(t int64, m int) int64

IncT increments a timstamp (in seconds) by m minutes.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal marshals v into json bytes.

func MarshalToString

func MarshalToString(v interface{}) (string, error)

MarshalToString marshals v into a string.

func Nano

func Nano() int64

Nano returns the curent time in miliseconds UTC

func Now

func Now() int64

Now returns the curent time in seconds UTC

func RandString

func RandString() string

RandString returns a random string.

func RandStringId

func RandStringId() string

RandStringId returns a random id string.

func RandStringN

func RandStringN(n int) string

Randn returns a random string with length n.

func RandomToken

func RandomToken(prefix string) (string, error)

RandomToken generates a random token similar to a to a RFC 4122 UID

func Seed

func Seed(seed int64)

Seed sets the seed to seed.

func SetLogLevel added in v2.5.0

func SetLogLevel()

func ShortUUID

func ShortUUID() (string, error)

ShortUUID returns a short (6 bytes) UID

func SimpleUUID

func SimpleUUID() (string, error)

SimpleUUID generates a random UUID according to RFC 4122, without any dashes

func ToHour

func ToHour(t int64) int

ToHour retuns the hour of the day for the timestamp, in local time

func ToHourUTC

func ToHourUTC(t int64) int

ToHourUTC retuns the hour of the day for the timestamp, UTC time

func ToUTC

func ToUTC(t int64) string

ToUTC converts a timestamp to UTC timestamp

func ToWeekday

func ToWeekday(t int64) int

ToWeekday retuns the day of the week for the timestamp

func UUID

func UUID() (string, error)

UUID generates a random UUID according to RFC 4122

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals data bytes into v.

func UnmarshalFromReader

func UnmarshalFromReader(reader io.Reader, v interface{}) error

UnmarshalFromReader unmarshals v from reader.

func UnmarshalFromString

func UnmarshalFromString(str string, v interface{}) error

UnmarshalFromString unmarshals v from str.

Types

type AnyType

type AnyType = interface{}

AnyType can be used to hold any type.

type PlaceholderType

type PlaceholderType = struct{}

PlaceholderType represents a placeholder type.

var Placeholder PlaceholderType

Placeholder is a placeholder object that can be used globally.

Jump to

Keyboard shortcuts

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