Files
gf/.example/container/gvar/var.go

34 lines
417 B
Go
Raw Normal View History

2018-10-10 15:24:30 +08:00
package main
import (
2019-04-03 00:03:46 +08:00
"fmt"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/frame/g"
2018-10-10 15:24:30 +08:00
)
func main() {
2019-04-03 00:03:46 +08:00
var v g.Var
2018-10-10 15:24:30 +08:00
2019-04-03 00:03:46 +08:00
v.Set("123")
2018-10-10 15:24:30 +08:00
2019-04-03 00:03:46 +08:00
fmt.Println(v.Val())
2018-10-10 15:24:30 +08:00
2019-04-03 00:03:46 +08:00
// 基本类型转换
fmt.Println(v.Int())
fmt.Println(v.Uint())
fmt.Println(v.Float64())
2018-10-10 15:24:30 +08:00
2019-04-03 00:03:46 +08:00
// slice转换
fmt.Println(v.Ints())
fmt.Println(v.Floats())
fmt.Println(v.Strings())
2018-10-10 15:24:30 +08:00
2019-04-03 00:03:46 +08:00
// struct转换
type Score struct {
Value int
}
s := new(Score)
v.Struct(s)
fmt.Println(s)
2018-10-10 15:24:30 +08:00
}