forked from grpc-ecosystem/grpc-gateway
/
main.go
43 lines (35 loc) · 852 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"flag"
"net/http"
"github.com/gengo/grpc-gateway/runtime"
"github.com/golang/glog"
"golang.org/x/net/context"
)
var (
echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of EchoService")
abeEndpoint = flag.String("more_endpoint", "localhost:9090", "endpoint of ABitOfEverythingService")
)
func Run() error {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
mux := runtime.NewServeMux()
err := RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint)
if err != nil {
return err
}
err = RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx, mux, *abeEndpoint)
if err != nil {
return err
}
http.ListenAndServe(":8080", mux)
return nil
}
func main() {
flag.Parse()
defer glog.Flush()
if err := Run(); err != nil {
glog.Fatal(err)
}
}