-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.go
45 lines (40 loc) · 981 Bytes
/
helpers.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
package router
import (
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"os"
"regexp"
"strconv"
)
func GRPCSettings() []grpc.ServerOption {
return []grpc.ServerOption{
grpc.KeepaliveParams(
keepalive.ServerParameters{
Time: keepaliveTime,
Timeout: keepaliveTimeout,
}),
grpc.KeepaliveEnforcementPolicy(
keepalive.EnforcementPolicy{
MinTime: keepaliveTime / 2,
PermitWithoutStream: true,
}),
}
}
func MustParseOrdinal(ordinalStr string) uint32 {
if ordinalStr == "" {
hostname, err := os.Hostname()
if err != nil {
panic(fmt.Errorf("unable to read hostname, and ordinal not set: %s", err))
}
ordinalStr = regexp.MustCompile(`\d+$`).FindString(hostname)
if ordinalStr == "" {
panic("hostname does not have the form .*\\d+$")
}
}
ordinal, err := strconv.ParseInt(ordinalStr, 10, 32)
if err != nil {
panic(fmt.Errorf("unable to parse ordinal: %s", err))
}
return uint32(ordinal)
}