2020-05-13 06:57:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-19 10:12:18 +00:00
|
|
|
"encoding/gob"
|
2020-05-13 06:57:57 +00:00
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
|
|
)
|
|
|
|
|
2020-05-19 10:12:18 +00:00
|
|
|
var cl *KeyList = &KeyList{}
|
2020-05-13 06:57:57 +00:00
|
|
|
|
|
|
|
func init() {
|
2020-05-19 10:12:18 +00:00
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// 注册序列化结构
|
|
|
|
gob.RegisterName("workshop.KeyList", KeyList{})
|
|
|
|
gob.RegisterName("workshop.Country", Country{})
|
|
|
|
gob.RegisterName("workshop.LastName", LastName{})
|
|
|
|
gob.RegisterName("workshop.FirstName", FirstName{})
|
|
|
|
gob.RegisterName("workshop.NameCode", NameCode{})
|
2020-05-19 10:12:18 +00:00
|
|
|
|
2020-05-13 06:57:57 +00:00
|
|
|
f, err := os.OpenFile("./my.log", os.O_CREATE|os.O_RDWR, os.ModePerm)
|
|
|
|
CheckErrorPanic(err)
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// 加载序列化结构
|
2020-06-02 07:26:53 +00:00
|
|
|
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)
|
2020-06-03 03:31:35 +00:00
|
|
|
|
2020-05-13 06:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// gserver := grpc.NewServer()
|
|
|
|
mux := runtime.NewServeMux()
|
|
|
|
|
2020-06-03 03:31:35 +00:00
|
|
|
// 注册rpc http接口 根据protobuf协议生成
|
2020-05-22 07:39:43 +00:00
|
|
|
RegisterNameHandlerServer(ctx, mux, &nameserver{})
|
|
|
|
RegisterCountryHandlerServer(ctx, mux, &countryserver{})
|
|
|
|
RegisterProvinceAreaCityHandlerServer(ctx, mux, &provinceserver{})
|
|
|
|
RegisterWayHandlerServer(ctx, mux, &wayserver{})
|
|
|
|
RegisterBuildingHandlerServer(ctx, mux, &buildingserver{})
|
2020-05-19 10:12:18 +00:00
|
|
|
|
2020-06-02 07:26:53 +00:00
|
|
|
log.Println("Listen 4433")
|
2020-05-13 06:57:57 +00:00
|
|
|
log.Fatal(http.ListenAndServe(":4433", mux))
|
2020-05-19 10:12:18 +00:00
|
|
|
|
2020-05-13 06:57:57 +00:00
|
|
|
}
|