-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrpc.go
More file actions
35 lines (29 loc) · 841 Bytes
/
grpc.go
File metadata and controls
35 lines (29 loc) · 841 Bytes
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
//go:generate go-bindata data/...
package main
import (
"crypto/tls"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/transport"
)
func opts() (opts []grpc.ServerOption) {
certPEMBlock, _ := Asset("data/server.pem")
keyPEMBlock, _ := Asset("data/server.key")
cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
check(err)
creds := credentials.NewServerTLSFromCert(&cert)
opts = append(opts, grpc.Creds(creds))
opts = append(opts, grpc.MaxMsgSize(MaxGrpcMessageSize))
return
}
func NewServer() *grpc.Server {
return grpc.NewServer(opts()...)
}
func MethodFromContext(ctx context.Context) string {
stream, ok := transport.StreamFromContext(ctx)
if !ok {
panic("babl-server: grpc: MethodFromContext: No Stream in Context")
}
return stream.Method()
}