github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/gateway/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "net/http" 6 7 "context" 8 "github.com/golang/glog" 9 "github.com/grpc-ecosystem/grpc-gateway/runtime" 10 "google.golang.org/grpc" 11 12 hello "github.com/micro/go-micro/examples/gateway/proto/hello" 13 ) 14 15 var ( 16 // the go.micro.srv.greeter address 17 endpoint = flag.String("endpoint", "localhost:9090", "go.micro.srv.greeter address") 18 ) 19 20 func run() error { 21 ctx := context.Background() 22 ctx, cancel := context.WithCancel(ctx) 23 defer cancel() 24 25 mux := runtime.NewServeMux() 26 opts := []grpc.DialOption{grpc.WithInsecure()} 27 28 err := hello.RegisterSayHandlerFromEndpoint(ctx, mux, *endpoint, opts) 29 if err != nil { 30 return err 31 } 32 33 return http.ListenAndServe(":8080", mux) 34 } 35 36 func main() { 37 flag.Parse() 38 39 defer glog.Flush() 40 41 if err := run(); err != nil { 42 glog.Fatal(err) 43 } 44 }