Created
April 20, 2017 01:11
-
-
Save hadv/9ec73d796a0dd9995fa64b97fd7ff2c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
“flag” | |
“net/http” | |
“github.com/gengo/grpc-gateway/runtime” | |
“github.com/golang/glog” | |
echo “github.com/hadv/grpc/echo” | |
“golang.org/x/net/context” | |
“google.golang.org/grpc” | |
) | |
var ( | |
echoEndpoint = flag.String(“echo_endpoint”, “localhost:9090”, “endpoint of EchoService”) | |
) | |
func Run(address string, opts …runtime.ServeMuxOption) error { | |
ctx := context.Background() | |
ctx, cancel := context.WithCancel(ctx) | |
defer cancel() | |
mux := runtime.NewServeMux(opts…) | |
dialOpts := []grpc.DialOption{grpc.WithInsecure()} | |
err := echo.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, dialOpts) | |
if err != nil { | |
return err | |
} | |
http.ListenAndServe(address, mux) | |
return nil | |
} | |
func main() { | |
flag.Parse() | |
defer glog.Flush() | |
if err := Run(“:8080”); err != nil { | |
glog.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment