gotils

package module
v0.0.0-...-b0d1fdf Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 23 Imported by: 2

README

gotils

Quick and Dirty Go (golang) utils.

builds

Build Status

Documentation

Index

Constants

View Source
const StringNone = ""

Variables

View Source
var (
	EmptyJSONBytes  = []byte("{}")
	EmptyJSONString = string(EmptyJSONBytes)
)
View Source
var ErrorInvalidId = errors.New("invalid Snowflake ID")

Functions

func CheckAll

func CheckAll(b, flags Bits) bool

func CheckAny

func CheckAny(b, flags Bits) bool

func CheckFatal

func CheckFatal(e error) error

CheckFatal checks the error and panics if it's not nil

func CheckNotFatal

func CheckNotFatal(e error) error

CheckNotFatal checks the error, logs it if not nil, and moves on

func DebugRuntimeCallerFuncion

func DebugRuntimeCallerFuncion(targetName string) string

func DebugToJSONStringNoIndentEscaped

func DebugToJSONStringNoIndentEscaped(o interface{}) string

func Explode2

func Explode2(x string) (a, b string)

Explode2 splits the string by a seperator 'sep'

func Explode3

func Explode3(x string) (a, b, c string)

Explode3 splits the string by a seperator 'sep'

func FromGOB

func FromGOB(network []byte, o interface{}) error

FromGOB parse GOB blob into an interface object

func FromJSONBytes

func FromJSONBytes(buf []byte, o interface{}) error

FromJSONBytes parses JSON bytes buffer into o

func FromJSONString

func FromJSONString(buf string, o interface{}) error

FromJSONString parses JSON string into o

func GenerateUniqueID

func GenerateUniqueID(idType string, nowLocal time.Time) (string, string)

GenerateUniqueID sorted by time

func HTTPBytesGet

func HTTPBytesGet(url string) ([]byte, *http.Header, error)

HTTPBytesGet fetches payload into a buffer

func HTTPJSONGet

func HTTPJSONGet(url string, o interface{}, username string, password string) error

HTTPJSONGet getches JSON from the given url

func HTTPParamGetInt

func HTTPParamGetInt(req *http.Request, key string, defaultValue int) int

HTTPParamGetInt get an integer param from an HTTP request

func HTTPParamGetString

func HTTPParamGetString(req *http.Request, key string, defaultValue string) string

HTTPParamGetString get a string param from an HTTP request

func HTTPXMLGet

func HTTPXMLGet(url string, o interface{}) error

HTTPXMLGet fetches XML payload and parses it into o

func Implode2

func Implode2(a, b string) string

Implode2 cancatenates two strings with a seperator 'sep'

func Implode3

func Implode3(a, b, c string) string

Implode3 cancatenates two strings with a seperator 'sep'

func IsPrivateIPV4Get

func IsPrivateIPV4Get(ip net.IP) bool

IsPrivateIPV4Get checks if the given IP is private (AWS/EC2)

func IsSetAll

func IsSetAll(b, flags Bits) bool

func IsSetAny

func IsSetAny(b, flags Bits) bool

func KeepShort

func KeepShort(s *string, maxLenght int) *string

KeepShort keeps the string short

func MD5Hash

func MD5Hash(text string) string

MD5Hash computes MD5 hash on text

func PrivateIPV4Get

func PrivateIPV4Get() (net.IP, error)

PrivateIPV4Get gets the private IP of the current AWS/EC2 server

func PrivateIPV4GetLower16

func PrivateIPV4GetLower16() (uint16, error)

PrivateIPV4GetLower16 gets the lower 16 bits of the IP address

func PrivateIPV4GetLower16OrDie

func PrivateIPV4GetLower16OrDie() uint16

PrivateIPV4GetLower16OrDie gets the lower 16 bits of the IP address

func PrivateIPV4GetLower32OrDie

func PrivateIPV4GetLower32OrDie() uint32

func ReadJSONFile

func ReadJSONFile(filename string, o interface{}) error

ReadJSONFile reads a JSON file into o

func ReadJSONFileCompressed

func ReadJSONFileCompressed(filename string, o interface{}) error

ReadJSONFileCompressed read compressed (gzip) JSON file

func ReadXMLFile

func ReadXMLFile(filename string, o interface{}) error

ReadXMLFile reads an XML file into o

func SnowflakeExtractGroup

func SnowflakeExtractGroup(id string, idType string) string

func SnowflakeID

func SnowflakeID(idType string, nowLocal time.Time) string

func SnowflakeIDWithGroup

func SnowflakeIDWithGroup(idType string, nowLocal time.Time) (groupID string, uniqueID string)

func ToGOB

func ToGOB(o interface{}) []byte

ToGOB serialize an interface into a GOB

func ToJSONBytes

func ToJSONBytes(v interface{}) []byte

ToJSONBytes serializes v into a buffer of JSON bytes

func ToJSONBytesNoIndent

func ToJSONBytesNoIndent(v interface{}) []byte

ToJSONBytesNoIndent serializes v into a buffer of JSON bytes

func ToJSONBytesNoIndentOrError

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

ToJSONBytesNoIndent serializes v into a buffer of JSON bytes

func ToJSONBytesOrError

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

ToJSONBytesOrError serializes v into a buffer of JSON bytes

func ToJSONString

func ToJSONString(v interface{}) string

ToJSONString serializes v into a JSON string

func ToJSONStringNoIndent

func ToJSONStringNoIndent(v interface{}) string

ToJSONStringNoIndent serialize v into a JSON string

func ToJSONStringOrError

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

ToJSONStringOrError serializes v into a JSON string

func ToXMLString

func ToXMLString(v interface{}) string

ToXMLString serializes v into an XML string

func TouchFile

func TouchFile(filename string) error

TouchFile creates a filename if it doesn't exist yet

func URLIsValid

func URLIsValid(urlString string) error

URLIsValid check if a given string is a valid URL

func WriteJSONFile

func WriteJSONFile(filename string, o interface{}) error

WriteJSONFile writes the object 'o' as JSON into the given file

func WriteJSONFileCompressed

func WriteJSONFileCompressed(filename string, o interface{}) error

WriteJSONFileCompressed write o as a compressed JSON file (gzip)

Types

type Bits

type Bits uint64

func Clear

func Clear(b, flag Bits) Bits

func Set

func Set(b, flag Bits) Bits

func Toggle

func Toggle(b, flag Bits) Bits

func (*Bits) CheckAll

func (t *Bits) CheckAll(flags Bits) bool

func (*Bits) CheckAny

func (t *Bits) CheckAny(flags Bits) bool

func (*Bits) Clear

func (t *Bits) Clear(flag Bits)

func (*Bits) IsSetAll

func (t *Bits) IsSetAll(flags Bits) bool

func (*Bits) IsSetAny

func (t *Bits) IsSetAny(flags Bits) bool

func (*Bits) Set

func (t *Bits) Set(flag Bits)

func (*Bits) Toggle

func (t *Bits) Toggle(flag Bits)

type StructTraverseTraverser

type StructTraverseTraverser struct {
	Params map[string]interface{}
}
Traverse the structs recursively allowing to modify the instances in place if required.
For example - hiding or updating values selectively just before serializing to JSON.

*

func CreateStructTraverseContext

func CreateStructTraverseContext(params map[string]interface{}) *StructTraverseTraverser

func (*StructTraverseTraverser) Traverse

func (t *StructTraverseTraverser) Traverse(objectToTraverse interface{}) error

type StructTraverseVisitor

type StructTraverseVisitor interface {
	StructTraverseVisitor(traverseContext *StructTraverseTraverser) error
}
Interface to be adopted for instances that want to hide / modify fields by StructTraverseTraverser

*

type Time

type Time time.Time

func FromUnix

func FromUnix(sec int64) Time

func FromUnixMilli

func FromUnixMilli(sec int64) Time

func Now

func Now() Time

func (Time) Local

func (t Time) Local() time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

func (Time) Time

func (t Time) Time() time.Time

func (Time) UTC

func (t Time) UTC() time.Time

func (Time) Unix

func (t Time) Unix() int64

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(s []byte) (err error)

Jump to

Keyboard shortcuts

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