utils

package
v0.0.0-...-f39a356 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: GPL-2.0, GPL-2.0 Imports: 27 Imported by: 0

README

utils

Utilities

Documentation

Index

Constants

View Source
const (
	NonConfusingCharacters         = "23456789ABCDEFGHJKLMNPRSTUVWXYZ"
	NonConfusingCharactersSoftPair = "ABCDEFGHJLMNOPRSTUVWYZ"
)
View Source
const (
	ISO8601DayTimeFormat  = "150405"
	ISO8601DateTimeFormat = "20060102150405"
	ISO8601DateFormat     = "20060102"
)

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) (string, error)

func ConstantTimeEqualBytes

func ConstantTimeEqualBytes(b1, b2 []byte) bool

func ConstantTimeEqualString

func ConstantTimeEqualString(s1, s2 string) bool

func DecodeBigInt

func DecodeBigInt(chars, encoded string) *big.Int

func DecodeBytes

func DecodeBytes(chars, encoded string) []byte

func EncodeBigInt

func EncodeBigInt(chars string, bigInt *big.Int) string

func EncodeBytes

func EncodeBytes(chars string, b []byte) string

func EncodeToken

func EncodeToken(token AccessToken, timeout time.Duration) (result string, err error)

func Example

func Example(t reflect.Type) (result interface{})

func GenerateFlags

func GenerateFlags(i interface{}) (result []string, err error)

GenerateFlags will generate command line flags matching the fields of the provided interface (being a struct pointer).

Any fields tagged with `flag` will be named like the value of the `flag` tag.

func GitBranch

func GitBranch(dir string) (branch string, err error)

func GitCommitted

func GitCommitted(dir string) (result bool, err error)

func GitRevision

func GitRevision(dir string) (rev string, err error)

func InSlice

func InSlice(slice interface{}, needle interface{}) (result bool, err error)

func IsNil

func IsNil(i interface{}) bool

func ParseAccessTokens

func ParseAccessTokens(s []byte, token AccessToken)

func ParseFlags

func ParseFlags(i interface{}, defaultMap map[string]string) (err error)

ParseFlags will parse command line flags according the fields of the provided interface (being a struct pointer).

It supports bool, int and string fields, and the flag name will be taken from the field name (or the `flag` tag if present).

`flag_default` tags will provide default values if no flag is provided.

func Prettify

func Prettify(obj interface{}) string

func RandomString

func RandomString(i int) string

func RandomStringFrom

func RandomStringFrom(chars string, i int) string

func ReflectCopy

func ReflectCopy(source, destinationPointer interface{})

func Stack

func Stack() string

func StripStack

func StripStack(err error) (result error)

func ToCurl

func ToCurl(req *http.Request) string

For debugging use. Converts a http.Request to a curl string for copy'n'paste to terminal

func UpdateGitRevision

func UpdateGitRevision(dir, destination string) (err error)

func ValidateFuncInput

func ValidateFuncInput(f interface{}, in []reflect.Type) error

func ValidateFuncInputs

func ValidateFuncInputs(f interface{}, ins ...[]reflect.Type) (errs []error)

func ValidateFuncOutput

func ValidateFuncOutput(f interface{}, out []reflect.Type) error

func ValidateFuncOutputs

func ValidateFuncOutputs(f interface{}, outs ...[]reflect.Type) (errs []error)

Types

type AccessToken

type AccessToken interface {
	Encode() ([]byte, error)
	Scopes() []string
}

func ParseAccessToken

func ParseAccessToken(d string, dst AccessToken) (result AccessToken, err error)

ParseAccessToken will return the AccessToken encoded in d. If dst is provided it will encode into it.

type Base64String

type Base64String string

func (Base64String) Bytes

func (self Base64String) Bytes() (result []byte, err error)

func (Base64String) MarshalJSON

func (self Base64String) MarshalJSON() (result []byte, err error)

func (Base64String) String

func (self Base64String) String() string

func (*Base64String) UnmarshalJSON

func (self *Base64String) UnmarshalJSON(b []byte) (err error)

type ByteString

type ByteString struct {
	Bytes []byte
}

func (ByteString) MarshalJSON

func (self ByteString) MarshalJSON() ([]byte, error)

func (ByteString) String

func (self ByteString) String() string

func (*ByteString) UnmarshalJSON

func (self *ByteString) UnmarshalJSON(b []byte) error

type DefaultStackError

type DefaultStackError struct {
	Source error
	Stack  string
}

func (DefaultStackError) Error

func (self DefaultStackError) Error() string

func (DefaultStackError) GetStack

func (self DefaultStackError) GetStack() string

type MultiError

type MultiError []error

func (MultiError) Error

func (self MultiError) Error() string

type Parallelizer

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

func (*Parallelizer) Start

func (self *Parallelizer) Start(f func() error)

func (*Parallelizer) Wait

func (self *Parallelizer) Wait() (err error)

type StackError

type StackError interface {
	GetStack() string
	Error() string
}

func Errorf

func Errorf(f string, args ...interface{}) StackError

func NewError

func NewError(source error) StackError

type SyncLock

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

func (*SyncLock) Sync

func (self *SyncLock) Sync(s interface{}, f func() error) error

Sync will run only one f at a time for this s in this SyncLock.

type Time

type Time struct {
	time.Time
}

func (Time) MarshalJSON

func (self Time) MarshalJSON(args ...interface{}) ([]byte, error)

func (*Time) String

func (self *Time) String() string

func (*Time) UnmarshalJSON

func (self *Time) UnmarshalJSON(b []byte, args ...interface{}) (err error)

type WaitOnce

type WaitOnce struct {
	SyncLock
	// contains filtered or unexported fields
}

func (*WaitOnce) Once

func (self *WaitOnce) Once(s interface{}, f func() error) (err error)

Once will run only one f, ever, for this s in this WaitOnce, and not return until it has run at least once.

Directories

Path Synopsis
gae
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
key
web

Jump to

Keyboard shortcuts

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