data_workshop/main.go

51 lines
820 B
Go
Raw Normal View History

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
gob.Register(KeyList{})
gob.Register(Country{})
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())
}
func main() {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// gserver := grpc.NewServer()
mux := runtime.NewServeMux()
2020-05-19 10:12:18 +00:00
ns := &nameserver{}
cs := &countryserver{}
ps := &provinceserver{}
2020-05-19 10:12:18 +00:00
RegisterNameHandlerServer(ctx, mux, ns)
RegisterCountryHandlerServer(ctx, mux, cs)
RegisterProvinceAreaCityHandlerServer(ctx, mux, ps)
2020-05-19 10:12:18 +00:00
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
}