42 lines
800 B
Go
42 lines
800 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"github.com/golang/glog"
|
|
"golang.org/x/net/context"
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"google.golang.org/grpc"
|
|
pb "loafle.com/overflow/overflow_api_service/grpc"
|
|
"net/http"
|
|
)
|
|
|
|
var (
|
|
overflowEndpoint = flag.String("echo_endpoint", "localhost:9090", "/v1/overflow/services")
|
|
)
|
|
|
|
func runGwRpc() (err error) {
|
|
ctx := context.Background()
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
defer cancel()
|
|
|
|
mux := runtime.NewServeMux()
|
|
opts := []grpc.DialOption{grpc.WithInsecure()}
|
|
|
|
err = pb.RegisterOverflowGatewayHandlerFromEndpoint(ctx, mux, *overflowEndpoint, opts)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return http.ListenAndServe(":8080", mux)
|
|
}
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
defer glog.Flush()
|
|
|
|
if err := runGwRpc(); err != nil {
|
|
glog.Fatal(err)
|
|
}
|
|
}
|