-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
52 lines (45 loc) · 1022 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"os"
"bufio"
)
type Address struct {
City string
Street string
}
type People struct {
Name string
Age int
sex string
Addr []Address
}
func add(a int, b int) *int {
r := new(int)
*r = a + b
return r
}
func main() {
vars := map[string]interface{}{
"numArray":[]int{3, 5, 6},
"idx": 3,
"func_add": add,
"peoples":[]People{
People{"wang", 15, "male", []Address{Address{"chengdu", "xinan"}, },},
People{"li", 27, "female", []Address{Address{"chengdu", "erhuan"}, Address{"beijing", "hh"},},},
},
}
fmt.Printf("vars -> %#v\n", vars)
stdin := bufio.NewReader(os.Stdin)
for {
fmt.Print("> ")
line, err := stdin.ReadString('\n')
if err != nil { break }
v, err := Eval(line, vars)
if err != nil {
fmt.Printf("Eval error : %#v\n", err.Error())
continue
}
fmt.Printf("%#v\n", v)
}
}