convert

package
v1.7.0-uptimefronte.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolStringToInt

func BoolStringToInt(s string) int

BoolStringToInt helper to deal with get param bools that convert over to 1 | 0 for the db

func BoolToInt

func BoolToInt(b bool) int

IntToBool helper used with sql conversion as sqlite has no boolean type, they are stored as 1 (true) or 0

func Curr added in v1.0.0

func Curr(s interface{}, symbol string) string

Curr generates a currency formated string from either a string or float64 value and prepends the symbol to the start Will round to nearest .2 Returns <symbol>0.0 by default

func Dict added in v1.0.0

func Dict(values ...any) (dict map[string]any)

Dict generates a map from an even number of arguments (key, value) Used within templates to merge data

func FloatString added in v1.7.0

func FloatString(s interface{}, layout string) string

func IntToBool

func IntToBool(i int) bool

IntToBool helper used with sql conversion as sqlite has no boolean type, they are stored as 1 (true) or 0, this maps them back to a bool

func Map

func Map[T any](item T) (m map[string]interface{}, err error)

Map converts a structure into the map of interface by using json marshaling to convert between types

func Maps added in v1.0.0

func Maps[T any](item []T) (m []map[string]interface{}, err error)

Maps converts a slice of structures into the map of interface by using json marshaling to convert between types

func Marshal

func Marshal[T any](item T) (content []byte, err error)

Marshal is a local wrapper around json.MarshalIndent for consistency

func Marshals

func Marshals[T any](items []T) (content []byte, err error)

Marshals is also a wraper around MarshalIndent, used to keep naming convention of unmarshaling versions

func MustMarshal added in v1.0.0

func MustMarshal[T any](item T) (content []byte)

func Pascal added in v1.0.0

func Pascal(s string) string

func Percent added in v1.0.0

func Percent(got int, total int) string

Percent works out % value of items Used in templates Returns 2 decimals

func PermuteStrings added in v1.4.0

func PermuteStrings(parts ...[]string) (ret []string)

func PrettyString added in v1.0.0

func PrettyString[T any](item T) (s string)

PrettyString is similar to String, but retains the indentations

func String

func String[T any](item T) (s string)

String uses the json marshal to quickly convert any struct into a string for display

func Stringify

func Stringify(r *http.Response) (s string, b []byte)

Stringify returns the body content of a http.Response as both a string and []byte. Very helpful for debugging, testing and converting back and forth from the api.

func StripIntPrefix added in v1.0.0

func StripIntPrefix(s string) string

StripIntPrefix removes chunk of string before the first '.' - this is used in templates to remove integer indexes from strings - will remove all other . from the source string

func Title added in v1.0.0

func Title(s string) string

Title is used by template helpers to make a "pretty" versions of a column name

team_a => Team A

func Titles added in v1.3.0

func Titles(strs ...string) (str string)

func Unmap

func Unmap[T any](m map[string]interface{}) (item T, err error)

Unmap uses json marshaling to convert from a map back to a struct.

func Unmaps added in v1.0.0

func Unmaps[T any](m []map[string]interface{}) (items []T, err error)

Unmaps uses json marshaling to convert from a map back to a struct.

func Unmarshal

func Unmarshal[T any](content []byte) (item T, err error)

Unmarshal wraper json.Unmarshal and handles error messages etc

func UnmarshalR added in v1.0.0

func UnmarshalR[T any](r *http.Response) (item T, err error)

func Unmarshals

func Unmarshals[T any](content []byte) (items []T, err error)

Unmarshals wrapper for mutliple types for shorthand and deals with error logging

Types

This section is empty.

Jump to

Keyboard shortcuts

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