-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (32 loc) · 851 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"context"
"flag"
"log"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
v1 "github.com/marcosdias/tutorial-grpc-rest-api-go/gen/product/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var (
port = flag.String("port", "8081", "port is the port this server will use")
endpoint = flag.String("endpoint", "localhost:8080",
"endpoint is the gRPC server's address")
)
func main() {
flag.Parse()
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx := context.Background()
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
err := v1.RegisterProductServiceHandlerFromEndpoint(ctx, mux, *endpoint, opts)
if err != nil {
return err
}
return http.ListenAndServe(":"+*port, mux)
}