overflow_gateway_service/server/gwrpc.go

31 lines
670 B
Go
Raw Normal View History

2017-05-24 06:31:30 +00:00
package server
2017-05-23 10:08:11 +00:00
import (
"flag"
"golang.org/x/net/context"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
2017-05-29 11:32:23 +00:00
pb "git.loafle.net/overflow/overflow_api_service/grpc"
2017-05-23 10:08:11 +00:00
"net/http"
)
var (
overflowEndpoint = flag.String("echo_endpoint", "localhost:9090", "/v1/overflow/services")
)
2017-05-24 06:31:30 +00:00
func RunGwRpc() (err error) {
2017-05-23 10:08:11 +00:00
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)
2017-05-24 06:31:30 +00:00
}