Fix up host ports and env variables
This commit is contained in:
parent
7c830f58be
commit
98249948a1
8 changed files with 38 additions and 55 deletions
|
@ -2,44 +2,42 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
)
|
||||
|
||||
var endpoint = os.Getenv("GRPC_ENDPOINT")
|
||||
var address = os.Getenv("HOST_ADDRESS")
|
||||
|
||||
func run() error {
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// Create a new mux and register it with the gRPC engpoint
|
||||
var endpoint = os.Getenv("ROVE_GRPC")
|
||||
if len(endpoint) == 0 {
|
||||
log.Fatal("Must set $ROVE_GRPC")
|
||||
}
|
||||
|
||||
var address = os.Getenv("ROVE_HTTP")
|
||||
if len(address) == 0 {
|
||||
log.Fatal("Must set $ROVE_HTTP")
|
||||
}
|
||||
|
||||
// Create a new mux and register it with the gRPC endpoint
|
||||
fmt.Printf("Hosting reverse-proxy on %s for %s\n", address, endpoint)
|
||||
mux := runtime.NewServeMux()
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
if err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Start the HTTP server and proxy calls to gRPC endpoint when needed
|
||||
return http.ListenAndServe(address, mux)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
defer glog.Flush()
|
||||
|
||||
if err := run(); err != nil {
|
||||
glog.Fatal(err)
|
||||
if err := http.ListenAndServe(address, mux); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue