utils

package
v0.0.79 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 20 Imported by: 7

Documentation

Index

Constants

View Source
const (
	DATE_FORMAT     = "2006-01-02"
	DATETIME_FORMAT = "2006-01-02 03-04-05"
)
View Source
const (
	ErrCodeInvalidRequest     = 400
	ErrCodeInvalidCredentials = 401
	ErrCodeAuthorized         = 403
	ErrCodeEntityNotFound     = 404
)

Variables

This section is empty.

Functions

func AlphaReverseMap added in v0.0.64

func AlphaReverseMap(alphabet string, out map[rune]uint) map[rune]uint

func BatchGet added in v0.0.28

func BatchGet[T any](ids []string, reqMaker func(string) (T, error)) (out map[string]T)

func Call added in v0.0.48

func Call(req *http.Request) (response interface{}, err error)

func EncodeURIComponent added in v0.0.14

func EncodeURIComponent(str string) string

func EnsureDirOf

func EnsureDirOf(path string) error

func EnsureEnvOrDefault added in v0.0.56

func EnsureEnvOrDefault(currval string, envvar string, defaultValue string) string

func ExcelDecode added in v0.0.64

func ExcelDecode(encoded string, alphabet string, revmap map[rune]uint) uint64

func ExcelEncode added in v0.0.64

func ExcelEncode(value uint64, alphabet string) string

func ExpandUserPath

func ExpandUserPath(path string) string

func Filter added in v0.0.23

func Filter[T any](items []T, filtfunc func(T) bool) (out []T)

func FormatDate

func FormatDate(t time.Time) string

func FormatTime

func FormatTime(t time.Time) string

func GetEnvOrDefault added in v0.0.56

func GetEnvOrDefault(envvar string, defaultValue string, ensure bool) string

*

  • Gets the value of an environment value and if it is missing returns the
  • default value.

func GetEnvOrDefaultInt added in v0.0.64

func GetEnvOrDefaultInt(envvar string, defaultvalue int) (int, error)

func GetMapField added in v0.0.38

func GetMapField(input StringMap, fieldPath interface{}) (any, error)

func GetMapFieldForced added in v0.0.74

func GetMapFieldForced(input StringMap, fieldPath interface{}) any

func HTTPErrorCode added in v0.0.47

func HTTPErrorCode(err error) int

func IndexOf added in v0.0.38

func IndexOf[T any](items []T, matchfunc func(T) bool) int

func Insert added in v0.0.41

func Insert[T any](list []T, item T, index int) []T

*

  • A method to insert an item at an index in a slice.

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func JsonDecodeBytes

func JsonDecodeBytes(bytes []byte) (interface{}, error)

func JsonDecodeStr

func JsonDecodeStr(str string) (interface{}, error)

func JsonGet

func JsonGet(url string, onReq func(req *http.Request)) (interface{}, *http.Response, error)

func JsonReadFile added in v0.0.24

func JsonReadFile(path string) (interface{}, error)

func JsonToQueryString

func JsonToQueryString(json StringMap) string

func JsonWriteFile added in v0.0.24

func JsonWriteFile(data interface{}, path string, perm os.FileMode) error

func MakeUrl added in v0.0.48

func MakeUrl(host, path string, args string) (url string)

func Map added in v0.0.22

func Map[T any, U any](items []T, mapfunc func(T) U) (out []U)

func MapKeys added in v0.0.39

func MapKeys[K comparable, V any](input map[K]V) []K

func MapValues added in v0.0.39

func MapValues[V any, K comparable](input map[K]V) []V

func NeedsRefresh

func NeedsRefresh(refresh_type int32, last_refreshed_at time.Time, now time.Time) bool

func NewBytesRequest added in v0.0.48

func NewBytesRequest(method string, endpoint string, body []byte) (req *http.Request, err error)

func NewJsonRequest added in v0.0.48

func NewJsonRequest(method string, endpoint string, body StringMap) (req *http.Request, err error)

func NewRequest added in v0.0.48

func NewRequest(method string, endpoint string, bodyReader io.Reader) (req *http.Request, err error)

func OpenBrowser added in v0.0.4

func OpenBrowser(url string)

*

  • Opens the browser pointing to a given URL.

func PaddedWith added in v0.0.64

func PaddedWith(input string, padding byte) string

func ParseDate

func ParseDate(str string) time.Time

func ParseTime

func ParseTime(str string) time.Time

func PriceString

func PriceString(value float64) string

func RandString added in v0.0.55

func RandString(length int, chars string) string

func Reduce added in v0.0.64

func Reduce[T any, V any](input []T, reducer func(index int, item T, output V) V, out V) V

Types

type DefaultMap added in v0.0.18

type DefaultMap[V interface{}] struct {
	// contains filtered or unexported fields
}

func NewDefaultMap added in v0.0.18

func NewDefaultMap[V any](creator func(key string) V) *DefaultMap[V]

func (*DefaultMap[V]) Ensure added in v0.0.18

func (tm *DefaultMap[V]) Ensure(key string) V

func (*DefaultMap[V]) Get added in v0.0.18

func (tm *DefaultMap[V]) Get(key string) (V, bool)

type HTTPError added in v0.0.47

type HTTPError struct {
	Code    int
	Message string
}

func (*HTTPError) Error added in v0.0.47

func (t *HTTPError) Error() string

type StringMap

type StringMap = map[string]interface{}

func CopyMapFields added in v0.0.38

func CopyMapFields(input StringMap, output StringMap, field_paths ...interface{}) (StringMap, error)

*

  • Copy a value in a given field path from the source into a fieldpath in the dest if
  • a. source field path is valid and exists
  • b. dest field path is valid (or needs to be created).

func SetMapField added in v0.0.38

func SetMapField(input StringMap, fieldPath interface{}, value interface{}) (StringMap, error)

*

  • Sets a map field at a given field path ensuring that everything until the leaf is a dictionary indeed.

func SetMapFields added in v0.0.38

func SetMapFields(input StringMap, field_paths_and_values ...interface{}) (StringMap, error)

*

  • SetMapFields takes a map and a list of field paths and values and sets the values in the map
  • @param input the map to set the values in
  • @param field_paths_and_values a list of field paths and values. The field paths are strings separated by "/" and the values are the values to set
  • @return error if there is an error at the first fieldpath that failed.

Jump to

Keyboard shortcuts

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