49 lines
742 B
Go
49 lines
742 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/gob"
|
|
"log"
|
|
"math/rand"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
)
|
|
|
|
var cl *KeyList = &KeyList{}
|
|
|
|
func init() {
|
|
|
|
gob.Register(KeyList{})
|
|
|
|
gob.Register(Country{})
|
|
|
|
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()
|
|
|
|
ns := &nameserver{}
|
|
cs := &countryserver{}
|
|
|
|
RegisterNameHandlerServer(ctx, mux, ns)
|
|
RegisterCountryHandlerServer(ctx, mux, cs)
|
|
|
|
log.Fatal(http.ListenAndServe(":4433", mux))
|
|
|
|
}
|