pyraconv

package module
v0.0.0-...-7dca3cf Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2016 License: MIT Imports: 7 Imported by: 5

README

pyraconv is Go type conversion library

    go get github.com/CossackPyra/pyraconv

It is used convert interface{} after unmarshaling JSON

Example

package main

import (
	"encoding/json"
	"fmt"

	"github.com/CossackPyra/pyraconv"
)

func main() {

	arrjson := []string{`{}`,
		`{"x":"1234557", "u":"http://golang.org/"}`,
		`{"x":325436, "u":["http://golang.org/", "http://www.golang.org/"]}`}

	for _, json1 := range arrjson {
		var m1 map[string]interface{}
		e := json.Unmarshal([]byte(json1), &m1)
		if e != nil {
			continue
		}
		x := pyraconv.ToInt64(m1["x"])
		fmt.Println("X:", x)
		u := pyraconv.ToStringArray(m1["u"])
		for i1, url := range u {
			fmt.Println("URL:", i1, url)
		}
	}

}

Result

X: 0
X: 1234557
URL: 0 http://golang.org/
X: 325436
URL: 0 http://golang.org/
URL: 1 http://www.golang.org/

Doc: https://godoc.org/github.com/CossackPyra/pyraconv

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneObject

func CloneObject(a, b interface{})

CloneObject creates copy of object using GOB.

func MovingExpAvg

func MovingExpAvg(value float64, oldValue float64, ftime float64, time float64) (r float64)

func MovingExpAvg32

func MovingExpAvg32(value float32, oldValue float32, ftime float32, time float32) (r float32)

func ReverseMovingExpAvg

func ReverseMovingExpAvg(r float64, oldValue float64, ftime float64, time float64) (value float64)

func ReverseMovingExpAvg32

func ReverseMovingExpAvg32(r float32, oldValue float32, ftime float32, time float32) (value float32)

func TimeSince

func TimeSince(t1 time.Time) (since string)

}

func ToBool

func ToBool(i1 interface{}) bool

ToBool converts interface{} to bool

func ToFloat32

func ToFloat32(i1 interface{}) float32

ToFloat64 converts interface{} to float64

func ToFloat64

func ToFloat64(i1 interface{}) float64

ToFloat64 converts interface{} to float64

func ToInt64

func ToInt64(i1 interface{}) int64

ToInt64 converts interface{} to int64

func ToInterfaceArray

func ToInterfaceArray(i1 interface{}) []interface{}

ToInterfaceArray converts interface{} to []interface{} and never returns nil

func ToInterfaceMap

func ToInterfaceMap(i1 interface{}) map[string]interface{}

ToInterfaceMap converts interface{} to map[string]interface{} and never returns nil

func ToString

func ToString(i1 interface{}) string

ToString converts interface{} to string

func ToStringArray

func ToStringArray(i1 interface{}) []string

ToStringArray converts interface{} to []string and never returns nil

func ToStringMap

func ToStringMap(i1 interface{}) map[string]string

ToStringMap converts interface{} to map[string]string and never returns nil

Types

This section is empty.

Jump to

Keyboard shortcuts

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