generated from johanbrandhorst/grpc-gateway-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 1.53 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"io/ioutil"
"mime"
"net"
"net/http"
"os"
"github.com/rakyll/statik/fs"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
"github.com/mrisney/grpc-gateway-boilerplate/gateway"
"github.com/mrisney/grpc-gateway-boilerplate/insecure"
pbExample "github.com/mrisney/grpc-gateway-boilerplate/proto"
"github.com/mrisney/grpc-gateway-boilerplate/server"
// Static files
_ "github.com/mrisney/grpc-gateway-boilerplate/statik"
)
// getOpenAPIHandler serves an OpenAPI UI.
// Adapted from https://github.com/philips/grpc-gateway-example/blob/a269bcb5931ca92be0ceae6130ac27ae89582ecc/cmd/serve.go#L63
func getOpenAPIHandler() http.Handler {
mime.AddExtensionType(".svg", "image/svg+xml")
statikFS, err := fs.New()
if err != nil {
panic("creating OpenAPI filesystem: " + err.Error())
}
return http.FileServer(statikFS)
}
func main() {
// Adds gRPC internal logs. This is quite verbose, so adjust as desired!
log := grpclog.NewLoggerV2(os.Stdout, ioutil.Discard, ioutil.Discard)
grpclog.SetLoggerV2(log)
addr := "0.0.0.0:10000"
lis, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalln("Failed to listen:", err)
}
s := grpc.NewServer(
// TODO: Replace with your own certificate!
grpc.Creds(credentials.NewServerTLSFromCert(&insecure.Cert)),
)
pbExample.RegisterUserServiceServer(s, server.New())
// Serve gRPC Server
log.Info("Serving gRPC on https://", addr)
go func() {
log.Fatal(s.Serve(lis))
}()
err = gateway.Run("dns:///" + addr)
log.Fatalln(err)
}