45 lines
792 B
Go
45 lines
792 B
Go
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)
|
|
}
|
|
}
|