convertor

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

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 CopyProperties

func CopyProperties[T, U any](dst *U, src T) error

CopyProperties copies each field from the source into the destination. It recursively copies struct pointers and interfaces that contain struct pointers.

func DecodeByte

func DecodeByte(data []byte, target any) error

DecodeByte decode byte slice data to target object.

func DeepClone

func DeepClone[T any](src T) T

DeepClone creates a deep copy of passed item. can't clone unexported field of struct

func EncodeByte

func EncodeByte(data any) ([]byte, error)

EncodeByte encode data to byte slice.

func GbkToUtf8

func GbkToUtf8(bs []byte) ([]byte, error)

GbkToUtf8 convert GBK encoding data to utf8 encoding data.

func MapToSlice

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

MapToSlice convert map to slice based on iteratee function.

func StructToMap

func StructToMap(value any) map[string]string

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 boolean.

func ToBytes

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

ToBytes convert value to byte slice.

func ToChannel

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

ToChannel convert a slice of elements to a read-only channel.

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 float64, if input is not a float return 0.0 and error.

func ToInt

func ToInt(value any) (int64, error)

ToInt convert value to int64 value, if input is not numerical, return 0 and error.

func ToInterface

func ToInterface(v reflect.Value) (value interface{}, ok bool)

ToInterface converts reflect value to its interface type.

func ToJson

func ToJson(value any) (string, error)

ToJson convert value to a json string.

func ToMap

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

ToMap convert a slice of structs to a map based on iteratee function.

func ToPointer

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

ToPointer returns a pointer to passed value.

func ToString

func ToString(value any) string

ToString convert value to string for number, string, []byte, will convert to string for other type (slice, map, array, struct) will call json.Marshal.

func Utf8ToGbk

func Utf8ToGbk(bs []byte) ([]byte, error)

Utf8ToGbk convert utf8 encoding data to GBK encoding data.

Types

This section is empty.

Jump to

Keyboard shortcuts

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