data_workshop/main.go

43 lines
764 B
Go
Raw Normal View History

2020-05-13 06:57:57 +00:00
package main
import (
"context"
"log"
"math/rand"
"net/http"
"os"
"time"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
)
var fnl *FirstNameList = &FirstNameList{}
var lnl *LastNameList = &LastNameList{}
func init() {
f, err := os.OpenFile("./my.log", os.O_CREATE|os.O_RDWR, os.ModePerm)
CheckErrorPanic(err)
log.SetOutput(f)
rand.Seed(time.Now().UnixNano())
LoadGob("./data/firstname.gob", fnl)
LoadGob("./data/lastname.gob", lnl)
}
func main() {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// gserver := grpc.NewServer()
mux := runtime.NewServeMux()
s := &nameserver{}
// RegisterNameServer(gserver, s)
RegisterNameHandlerServer(ctx, mux, s)
log.Fatal(http.ListenAndServe(":4433", mux))
}