convert

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChildMapsToStringKey

func ChildMapsToStringKey(convertMap map[string]interface{}) map[string]interface{}

ChildMapsToStringKey converts a map[interface{}]interface{} to map[string]interface{} recursively, assuming that the input map key values are explicitly of type string

func DecodeStruct

func DecodeStruct[T any](base64str string, template interface{}) (T, error)

DecodeStruct decodes a base64 encoded JSON struct representation to an instance of T

Notes
	template should be of type T
	template should be a pointer to a struct that is T (but not strictly
	*T, which is why it is typed as interface{})

func EncodeStruct

func EncodeStruct(obj interface{}) (string, error)

EncodeStruct converts a struct to JSON and Base64 encodes it

func GenericMapToStruct

func GenericMapToStruct(convertMap map[interface{}]interface{}, thing interface{}) error

GenericMapToStruct converts a map into a struct via Json Marshal/Unmarshal

func MapToStruct

func MapToStruct(convertMap map[string]interface{}, convertTo interface{}) error

MapToStruct converts a map into a struct via Json Marshal/Unmarshal

func MapToStructEx

func MapToStructEx(convertMap map[string]interface{}, convertTo interface{}) error

MapToStructEx converts a map into a struct via Json Marshal/Unmarshal and converts any child maps of type map[interface{}]interface{} to map[string]interface{}

func SimpleStructToMap

func SimpleStructToMap(something interface{}) (map[string]interface{}, error)

SimpleStructToMap Converts a struct to a map via JSON Marshalling

func ToArray

func ToArray(s interface{}) []interface{}

func ToArrayWithTag

func ToArrayWithTag(s interface{}, tagType string) (result []interface{})

func ToBool

func ToBool(input interface{}) (result bool, err error)

func ToFloat64

func ToFloat64(input interface{}) (result float64, err error)

ToFloat64 converts a value to a float64

func ToInt

func ToInt(input interface{}) (result int, err error)

ToInt converts a value to an int

func ToInt32

func ToInt32(input interface{}) (result int32, err error)

ToInt32 converts a value to an int32

func ToInt64

func ToInt64(input interface{}) (result int64, err error)

ToInt64 converts a value to an int64

func ToMap

func ToMap(s interface{}) (result map[string]interface{})

func ToMapWithStringKey

func ToMapWithStringKey(convertMap map[interface{}]interface{}) map[string]interface{}

ToMapWithStringKey converts a map[interface{}]interface{} to map[string]interface{} recursively, assuming that the input map key values are explicitly of type string

func ToMapWithTag

func ToMapWithTag(s interface{}, tagType string) map[string]interface{}

func ToString

func ToString(input interface{}) (result string, err error)

Types

type MapConverter

type MapConverter interface {
	ToMap(tagType string) map[string]interface{}
}

MapConverter is an interface that allows a struct type to specify a custom conversion of the struct instance to a map representation

Jump to

Keyboard shortcuts

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