conv2

package module
v0.0.0-...-62e5802 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 7 Imported by: 0

README

conv2

Biblioteca para conversão de dados em Go

Utilização

Import
import (
	"github.com/paulohalves/conv2"
)
XML to JSON
sample = "<xml>test</xml>"

result, err := XMLToJSON(sample)
if err != nil {
    panic("XMLToJSON: Erro durante a conversão do XML para o JSON")
}

// result: {"xml": "test"}
JSON to Map
sample := "{\"test\": \"json\", \"ok\": true}"

result, err := JSONToMap(sample)
if err != nil {
    panic("JSONToMap: Erro durante a conversão do JSON para Map")
}
Get String in Map
sample := "{\"test\": \"json\", \"ok\": true}"
val, _ := JSONToMap(sample)

result, err := GetStringInMap(val, "test")
if err != nil {
    panic("GetStringInMap: Erro durante a localização da string")
}

// result: "json"
Get Bool in Map
sample := "{\"test\": \"json\", \"ok\": true}"
val, _ := JSONToMap(sample)

result, err := GetBoolInMap(val, "ok")
if err != nil {
    panic("GetBoolInMap: Erro durante a localização do bool")
}

// result: true
Int to String
sampleInt := 12

result, err := ToString(sampleInt)
if err != nil {
    panic("ToString - Int: Erro durante a conversão do Int para String")
}

// result: "12"
Float to String
sampleFloat := 12.34

result, err := ToString(sampleFloat)
if err != nil {
    panic("ToString - Float: Erro durante a conversão do Float para String")
}

// result: "12.34"
Int to Bool
sampleInt := 1

result, err := ToBool(sampleInt)
if err != nil {
    panic("ToBool - Int: Erro durante a conversão do Bool para Int")
}

// result: true
Float to Bool
sampleFloat := 12.34

result, err := ToBool(sampleFloat)
if err != nil {
    panic("ToBool - Float: Erro durante a conversão do Bool para Float")
}

// result: true
String to Bool
sampleString := "1"

result, err := ToBool(sampleString)
if err != nil {
    panic("ToBool - String: Erro durante a conversão do Bool para String")
}

// result: true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayJSONToMap

func ArrayJSONToMap(data string) ([]map[string]interface{}, error)

ArrayJSONToMap -

func DebugStruct

func DebugStruct(data interface{}) (string, error)

DebugStruct -

func GetBoolInMap

func GetBoolInMap(data *gabs.Container, info string) (bool, error)

GetBoolInMap -

func GetInMap

func GetInMap(data *gabs.Container, info string) interface{}

GetInMap -

func GetStringInMap

func GetStringInMap(data *gabs.Container, info string) (string, error)

GetStringInMap -

func InterfaceToFloat64

func InterfaceToFloat64(data interface{}) float64

InterfaceToFloat64 -

func InterfaceToInt

func InterfaceToInt(data interface{}) int

InterfaceToInt -

func InterfaceToString

func InterfaceToString(data interface{}) string

InterfaceToString -

func JSONToMap

func JSONToMap(jsonString string) (*gabs.Container, error)

JSONToMap -

func ToBool

func ToBool(data interface{}) (bool, error)

ToBool -

func ToString

func ToString(data interface{}) (string, error)

ToString -

func XMLToJSON

func XMLToJSON(xmlString string) (string, error)

XMLToJSON -

Types

This section is empty.

Jump to

Keyboard shortcuts

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