Documentation ¶
Overview ¶
Package to provides a set of useful functions for type conversion.
Index ¶
- func Bool(v interface{}) (bool, error)
- func Float32(v interface{}) (float32, error)
- func Float64(v interface{}) (float64, error)
- func Int(v interface{}) (int, error)
- func Int16(v interface{}) (int16, error)
- func Int32(v interface{}) (int32, error)
- func Int64(v interface{}) (int64, error)
- func Int8(v interface{}) (int8, error)
- func String(v interface{}) (string, error)
- func Uint(v interface{}) (uint, error)
- func Uint16(v interface{}) (uint16, error)
- func Uint32(v interface{}) (uint32, error)
- func Uint64(v interface{}) (uint64, error)
- func Uint8(v interface{}) (uint8, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool convert given 'v' to boolean type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { b, err := to.Bool(0) if err != nil { panic(err) } fmt.Printf("%v type of %T", b, b) }
Output: false type of bool
func Float32 ¶
Float32 convert given 'v' to float32 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { f, err := to.Float32(true) if err != nil { panic(err) } fmt.Printf("%v type of %T", f, f) }
Output: 1 type of float32
func Float64 ¶
Float64 convert given 'v' to float64 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { f, err := to.Float64("3.14") if err != nil { panic(err) } fmt.Printf("%v type of %T", f, f) }
Output: 3.14 type of float64
func Int ¶
Int convert given 'v' to int type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { i, err := to.Int(-1) if err != nil { panic(err) } fmt.Printf("%v type of %T", i, i) }
Output: -1 type of int
func Int16 ¶
Int16 convert given 'v' to int16 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { i, err := to.Int16(-1) if err != nil { panic(err) } fmt.Printf("%v type of %T", i, i) }
Output: -1 type of int16
func Int32 ¶
Int32 convert given 'v' to int32 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { i, err := to.Int32(-1) if err != nil { panic(err) } fmt.Printf("%v type of %T", i, i) }
Output: -1 type of int32
func Int64 ¶
Int64 convert given 'v' to int64 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { i, err := to.Int64(-1) if err != nil { panic(err) } fmt.Printf("%v type of %T", i, i) }
Output: -1 type of int64
func Int8 ¶
Int8 convert given 'v' to int8 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { i, err := to.Int8(-1) if err != nil { panic(err) } fmt.Printf("%v type of %T", i, i) }
Output: -1 type of int8
func String ¶
String convert given 'v' to string type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { u, err := to.String(false) if err != nil { panic(err) } fmt.Printf("%v type of %T", u, u) }
Output: false type of string
func Uint ¶
Uint convert given 'v' to uint type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { u, err := to.Uint("1") if err != nil { panic(err) } fmt.Printf("%v type of %T", u, u) }
Output: 1 type of uint
func Uint16 ¶
Uint16 convert given 'v' to unt16 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { u, err := to.Uint16(0) if err != nil { panic(err) } fmt.Printf("%v type of %T", u, u) }
Output: 0 type of uint16
func Uint32 ¶
Uint32 convert given 'v' to uint32 type.
Example ¶
package main import ( "fmt" "github.com/n4x2/zoo/to" ) func main() { u, err := to.Uint32(1) if err != nil { panic(err) } fmt.Printf("%v type of %T", u, u) }
Output: 1 type of uint32
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.