Further consolidate the libraries
This commit is contained in:
44
service/grpc/examples/greeter/gateway/main.go
Normal file
44
service/grpc/examples/greeter/gateway/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
hello "github.com/micro/examples/grpc/gateway/proto/hello"
|
||||
)
|
||||
|
||||
var (
|
||||
// the go.micro.srv.greeter address
|
||||
endpoint = flag.String("endpoint", "localhost:9090", "go.micro.srv.greeter address")
|
||||
)
|
||||
|
||||
func run() error {
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
mux := runtime.NewServeMux()
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
|
||||
err := hello.RegisterSayHandlerFromEndpoint(ctx, mux, *endpoint, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return http.ListenAndServe(":8080", mux)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
defer glog.Flush()
|
||||
|
||||
if err := run(); err != nil {
|
||||
glog.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user