convertor

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 9 Imported by: 58

Documentation

Overview

Package convertor implements some functions to convert data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorHexToRGB

func ColorHexToRGB(colorHex string) (red, green, blue int)

ColorHexToRGB convert hex color to rgb color

func ColorRGBToHex

func ColorRGBToHex(red, green, blue int) string

ColorRGBToHex convert rgb color to hex color

func MapToSlice added in v2.1.2

func MapToSlice[T any, K comparable, V any](aMap map[K]V, iteratee func(K, V) T) []T

MapToSlice convert a map to a slice based on iteratee function

func StructToMap

func StructToMap(value any) (map[string]any, error)

StructToMap convert struct to map, only convert exported struct field map key is specified same as struct field tag `json` value

func ToBool

func ToBool(s string) (bool, error)

ToBool convert string to a boolean

func ToBytes

func ToBytes(value any) ([]byte, error)

ToBytes convert interface to bytes

func ToChannel added in v2.1.2

func ToChannel[T any](array []T) <-chan T

ToChannel convert a array of elements to a read-only channels

func ToChar

func ToChar(s string) []string

ToChar convert string to char slice

func ToFloat

func ToFloat(value any) (float64, error)

ToFloat convert value to a float64, if input is not a float return 0.0 and error

func ToInt

func ToInt(value any) (int64, error)

ToInt convert value to a int64, if input is not a numeric format return 0 and error

func ToJson

func ToJson(value any) (string, error)

ToJson convert value to a valid json string

func ToMap added in v2.1.2

func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V

ToMap convert a slice or an array of structs to a map based on iteratee function

func ToPointer added in v2.1.1

func ToPointer[T any](value T) *T

ToPointer returns a pointer to this value

func ToString

func ToString(value any) string

ToString convert value to string

Types

This section is empty.

Jump to

Keyboard shortcuts

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