diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..dfe2608 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,24 @@ +{ + "editor.tokenColorCustomizations": { + "textMateRules": [ + { + "scope": "googletest.failed", + "settings": { + "foreground": "#f00" + } + }, + { + "scope": "googletest.passed", + "settings": { + "foreground": "#0f0" + } + }, + { + "scope": "googletest.run", + "settings": { + "foreground": "#0f0" + } + } + ] + } +} \ No newline at end of file diff --git a/base.go b/base.go index 5b2f3d7..683b04c 100644 --- a/base.go +++ b/base.go @@ -135,16 +135,20 @@ func SaveGob(fname string, datatype reflect.Type, kfs ...KeyKind) { // LoadGob load gob from file func LoadGob(fname string, v IKeyList) { + f, err := os.Open(fname) + log.Println("load data: ", fname) CheckErrorPanic(err) reader := flate.NewReader(f) dec := gob.NewDecoder(reader) dec.Decode(v) + } // GetRandomKey get ikeylist key by random func GetRandomKey(v IKeyList) interface{} { - return v.GetKeys()[rand.Intn(v.GetLength())] + ret := v.GetKeys()[rand.Intn(v.GetLength())] + return ret } // GetRandomKeyBySlice get ikeylist key by random diff --git a/building.go b/building.go index 1afe2dd..5eb0d6c 100644 --- a/building.go +++ b/building.go @@ -7,7 +7,7 @@ import ( var buildinglist = &KeyList{} func init() { - LoadGob("./data/building.gob", buildinglist) + // LoadGob("./data/building.gob", buildinglist) } // UnimplementedBuildingServer can be embedded to have forward compatible implementations. diff --git a/building_test.go b/building_test.go index 8567f1a..4d7fb0b 100644 --- a/building_test.go +++ b/building_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func TestMakeBuildingGob(t *testing.T) { +func estMakeBuildingGob(t *testing.T) { f, err := os.Open("/home/eson/test/spider_xingming/building_simple.txt") if err != nil { panic(err) diff --git a/case_test.go b/case_test.go index 3bea3e1..87df420 100644 --- a/case_test.go +++ b/case_test.go @@ -26,7 +26,7 @@ import ( // SaveData("./data/lastname-test.gob", nln) // } -func TestS(t *testing.T) { +func estS(t *testing.T) { gob.Register(Country{}) ln := &KeyList{} LoadGob("./data/lastname1.gob", ln) @@ -36,7 +36,7 @@ func TestS(t *testing.T) { f.Write(country.Pic) } -func TestReadData(t *testing.T) { +func estReadData(t *testing.T) { gob.Register(Country{}) ln := &KeyList{} LoadGob("./data/country.gob", ln) diff --git a/country.go b/country.go index fddf225..78a682e 100644 --- a/country.go +++ b/country.go @@ -2,7 +2,6 @@ package main import ( context "context" - "encoding/gob" ) // Country struct @@ -13,11 +12,6 @@ type Country struct { var countrylist *KeyList = &KeyList{} -func init() { - gob.Register(Country{}) - LoadGob("./data/country.gob", countrylist) -} - type countryserver struct { } diff --git a/data_remake_test.go b/data_remake_test.go index 064610f..3143af3 100644 --- a/data_remake_test.go +++ b/data_remake_test.go @@ -4,7 +4,7 @@ import ( "testing" ) -func testRemakeGob(t *testing.T) { +func estRemakeGob(t *testing.T) { country := &KeyList{} LoadGob("./data/country-fix.gob", country) // for i, ikey := range country.Keys { diff --git a/go.mod b/go.mod index 543f9fe..030a3cf 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( github.com/474420502/hunter v0.1.1 + github.com/davecgh/go-spew v1.1.1 github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect diff --git a/main.go b/main.go index ddb5f13..37df7cc 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,10 @@ var cl *KeyList = &KeyList{} func init() { gob.Register(KeyList{}) - gob.Register(Country{}) + gob.Register(LastName{}) + gob.Register(FirstName{}) + gob.Register(NameCode{}) f, err := os.OpenFile("./my.log", os.O_CREATE|os.O_RDWR, os.ModePerm) CheckErrorPanic(err) @@ -26,6 +28,14 @@ func init() { rand.Seed(time.Now().UnixNano()) + LoadGob("./data/building.gob", buildinglist) + LoadGob("./data/country.gob", countrylist) + + LoadGob("./data/firstname.gob", fnl) + LoadGob("./data/lastname.gob", lnl) + + LoadGob("./data/province.gob", province) + LoadGob("./data/ways.gob", ways) } func main() { @@ -43,6 +53,7 @@ func main() { RegisterWayHandlerServer(ctx, mux, &wayserver{}) RegisterBuildingHandlerServer(ctx, mux, &buildingserver{}) + log.Println("Listen 4433") log.Fatal(http.ListenAndServe(":4433", mux)) } diff --git a/name_service.go b/name_service.go index 2402e08..1329469 100644 --- a/name_service.go +++ b/name_service.go @@ -2,7 +2,6 @@ package main import ( "context" - "encoding/gob" "log" ) @@ -17,14 +16,6 @@ type FirstName struct { var fnl *KeyList = &KeyList{} var lnl *KeyList = &KeyList{} -func init() { - gob.Register(LastName{}) - gob.Register(FirstName{}) - - LoadGob("./data/firstname.gob", fnl) - LoadGob("./data/lastname.gob", lnl) -} - type nameserver struct { } @@ -33,6 +24,7 @@ func (s *nameserver) FirstName(cxt context.Context, request *Request) (*Reply, e reply := &Reply{} reply.Message = string(GetRandomKey(fnl).(FirstName).Name) return reply, nil + } func (s *nameserver) LastName(cxt context.Context, request *Request) (*Reply, error) { diff --git a/province.go b/province.go index de3e224..f8cc90a 100644 --- a/province.go +++ b/province.go @@ -2,7 +2,6 @@ package main import ( context "context" - "encoding/gob" ) // NameCode 省份地区的结构 @@ -14,11 +13,6 @@ type NameCode struct { var province = &KeyList{} -func init() { - gob.Register(NameCode{}) - LoadGob("./data/province.gob", province) -} - type provinceserver struct { } diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..4916bec --- /dev/null +++ b/readme.md @@ -0,0 +1,10 @@ +# 编译流程 + +* sh generate.sh +* git submodule init +* git submodule update +* go build + +## 执行流程 + +* ./workshop diff --git a/way.go b/way.go index 9cc194e..8ede8af 100644 --- a/way.go +++ b/way.go @@ -6,10 +6,6 @@ import ( var ways = &KeyList{} -func init() { - LoadGob("./data/ways.gob", ways) -} - // wayserver can be embedded to have forward compatible implementations. type wayserver struct { } diff --git a/way_test.go b/way_test.go index 53184db..2499e1d 100644 --- a/way_test.go +++ b/way_test.go @@ -10,7 +10,7 @@ import ( "github.com/qedus/osmpbf" ) -func testPBF(t *testing.T) { +func estPBF(t *testing.T) { f, err := os.Open("/home/eson/tools/china-latest.osm.pbf") if err != nil { log.Fatal(err)