convertor

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 15 Imported by: 9

Documentation

Overview

Package convertor implements some functions to convert data.

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 CopyProperties added in v1.3.7

func CopyProperties(dst, src interface{}) error

CopyProperties copies each field from the source into the destination. It recursively copies struct pointers and interfaces that contain struct pointers. use json.Marshal/Unmarshal, so json tag should be set for fields of dst and src struct.

func DecodeByte added in v1.3.2

func DecodeByte(data []byte, target interface{}) error

DecodeByte decode byte data to target object

func DeepClone added in v1.3.6

func DeepClone(src interface{}) interface{}

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

func EncodeByte added in v1.3.2

func EncodeByte(data interface{}) ([]byte, error)

EncodeByte encode data to byte

func GbkToUtf8 added in v1.4.0

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

GbkToUtf8 convert GBK encoding data to utf8 encoding data.

func MapToStruct added in v1.4.3

func MapToStruct(m map[string]interface{}, structObj interface{}) error

MapToStruct converts map to struct

func StructToMap

func StructToMap(value interface{}) (map[string]interface{}, 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 interface{}) ([]byte, error)

ToBytes convert interface to bytes

func ToChannel added in v1.3.1

func ToChannel(array []interface{}) <-chan interface{}

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 interface{}) (float64, error)

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

func ToInt

func ToInt(value interface{}) (int64, error)

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

func ToInterface added in v1.3.9

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

ToInterface converts reflect value to its interface type.

func ToJson

func ToJson(value interface{}) (string, error)

ToJson convert value to a valid json string

func ToRawStdBase64 added in v1.4.3

func ToRawStdBase64(value interface{}) string

ToRawStdBase64 convert data to raw standard base64 encoding.

func ToRawUrlBase64 added in v1.4.3

func ToRawUrlBase64(value interface{}) string

ToRawUrlBase64 convert data to raw URL base64 encoding.

func ToStdBase64 added in v1.4.3

func ToStdBase64(value interface{}) string

ToStdBase64 convert data to standard base64 encoding.

func ToString

func ToString(value interface{}) string

ToString convert value to string

func ToUrlBase64 added in v1.4.3

func ToUrlBase64(value interface{}) string

ToUrlBase64 convert data to URL base64 encoding.

func Utf8ToGbk added in v1.4.0

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