forked from name5566/leaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request name5566#15 from ljfuyuan/mapsupport
add map support
- Loading branch information
Showing
4 changed files
with
80 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package recordfile | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type Mysql struct { | ||
Host, Port, User, Passwd, Db string | ||
} | ||
|
||
func Test_map(t *testing.T){ | ||
type Record struct { | ||
// index 0 | ||
IndexInt int "index" | ||
// index 1 | ||
IndexStr string "index" | ||
_Number int32 | ||
Str string | ||
Arr1 [2]int | ||
Arr2 [3][2]int | ||
Arr3 []int | ||
St struct { | ||
Name string "name" | ||
Num int "num" | ||
} | ||
Maps map[string]Mysql | ||
} | ||
|
||
rf, err := New(Record{}) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = rf.Read("test.txt") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
for i := 0; i < rf.NumRecord(); i++ { | ||
r := rf.Record(i).(*Record) | ||
t.Log(r.IndexInt) | ||
} | ||
|
||
r := rf.Index(2).(*Record) | ||
t.Log(r.Str) | ||
|
||
r = rf.Indexes(0)[2].(*Record) | ||
t.Log(r.Str) | ||
|
||
r = rf.Indexes(1)["three"].(*Record) | ||
t.Log(r.Str) | ||
t.Log(r.Arr1[1]) | ||
t.Log(r.Arr2[2][0]) | ||
t.Log(r.Arr3[0]) | ||
t.Log(r.St.Name) | ||
t.Log(r.Maps) | ||
|
||
//go test -v . | ||
//=== RUN Test_map | ||
//--- PASS: Test_map (0.00s) | ||
//map_test.go:41: 1 | ||
//map_test.go:41: 2 | ||
//map_test.go:41: 3 | ||
//map_test.go:45: cat | ||
//map_test.go:48: cat | ||
//map_test.go:51: book | ||
//map_test.go:52: 6 | ||
//map_test.go:53: 4 | ||
//map_test.go:54: 6 | ||
//map_test.go:55: name5566 | ||
//map_test.go:56: map[Mysql1:{127.0.0.1 3306 root db1} Mysql2:{127.0.0.2 3306 root ccc db2}] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
数字索引 字符串索引 数字类型 字符串类型 数组类型 嵌套数组 变长数组 结构体类型 | ||
1 one 0 knife "[1, 2]" "[[0,1], [1,2], [2,3]]" "[1, 2, 3]" "{""name"": ""name5566"", ""num"": 1}" | ||
2 two 0 cat "[3, 4]" "[[1,2], [2,3], [3,4]]" "[4, 5]" "{""name"": ""name5566"", ""num"": 2}" | ||
3 three 0 book "[5, 6]" "[[2,3], [3,4], [4,5]]" [6] "{""name"": ""name5566"", ""num"": 3}" | ||
数字索引 字符串索引 数字类型 字符串类型 数组类型 嵌套数组 变长数组 结构体类型 Map类型 | ||
1 one 0 knife "[1, 2]" "[[0,1], [1,2], [2,3]]" "[1, 2, 3]" "{""name"": ""name5566"", ""num"": 1}" "{""Mysql1"": {""Host"":""127.0.0.1"",""Port"":""3306"",""User"":""root"",""Passwd"":""111"",""Db"":""db1""},""Mysql2"": {""Host"":""127.0.0.2"",""Port"":""3306"",""User"":""root"",""Passwd"":""aaa"",""Db"":""db2""}}" | ||
2 two 0 cat "[3, 4]" "[[1,2], [2,3], [3,4]]" "[4, 5]" "{""name"": ""name5566"", ""num"": 2}" "{""Mysql1"": {""Host"":""127.0.0.1"",""Port"":""3306"",""User"":""root"",""Passwd"":"""",""Db"":""db1""},""Mysql2"": {""Host"":""127.0.0.2"",""Port"":""3306"",""User"":""root"",""Passwd"":""bbb"",""Db"":""db2""}}" | ||
3 three 0 book "[5, 6]" "[[2,3], [3,4], [4,5]]" [6] "{""name"": ""name5566"", ""num"": 3}" "{""Mysql1"": {""Host"":""127.0.0.1"",""Port"":""3306"",""User"":""root"",""Passwd"":"""",""Db"":""db1""},""Mysql2"": {""Host"":""127.0.0.2"",""Port"":""3306"",""User"":""root"",""Passwd"":""ccc"",""Db"":""db2""}}" |