-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
37 lines (33 loc) · 961 Bytes
/
conf.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 app
import (
"github.com/9d77v/band/pkg/env"
"github.com/9d77v/band/pkg/network"
)
type Conf struct {
AppName string `yaml:"app_name"`
ServiceName string
ServerHost string `yaml:"server_host"`
ServerPort uint64 `yaml:"server_port"`
EtcdAddress string `yaml:"etcd_address"`
MaxConns int `yaml:"max_conns"`
}
func FromEnv(serviceName string) Conf {
return Conf{
AppName: env.String("APP_NAME"),
ServiceName: serviceName,
ServerHost: env.String("SERVER_HOST"),
ServerPort: uint64(env.Int("SERVER_PORT")),
EtcdAddress: env.String("ETCD_ADDRESS"),
MaxConns: env.Int("MAX_CONNS", 10000),
}
}
func RPCFromEnv(serviceName string) Conf {
return Conf{
AppName: env.String("APP_NAME"),
ServiceName: serviceName,
ServerHost: network.GetNetworkIp(),
ServerPort: network.GetRandomPort(),
EtcdAddress: env.String("ETCD_ADDRESS", "http://localhost:2379"),
MaxConns: env.Int("MAX_CONNS", 10000),
}
}