convert

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 6 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 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)

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 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 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 Unmarshal

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

Unmarshal wraper json.Unmarshal and handles error messages etc

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