-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.io.go
60 lines (53 loc) · 1.74 KB
/
config.io.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
package elio
import (
"fmt"
"strings"
)
const (
// defaultReadBufferLen default read buffer len
defaultReadBufferLen int = 8 * 1024
// defaultInRange default in range
defaultInRange int = 0
// defaultInUrl default In url
defaultInUrl string = ""
// defaultInIoModel default IO model
defaultInIoModel string = "auto"
// defaultInCount default in count
defaultInCount int = 1
// defaultInWaitCount default in wait count
defaultInWaitCount int = 512
// defaultInNoDelay default in no delay
defaultInNoDelay bool = false
// defaultInRecvTimeo default in recv timeout
defaultInRecvTimeo int = -1
// defaultInRcvBuff default in rcv buff (KB)
defaultInRcvBuff int = 0
// defaultInSndBuff default in snd buff (KB)
defaultInSndBuff int = 0
// defaultInReusePort default in reuse port
defaultInReusePort bool = false
)
// ConfigIo config service
type ConfigIo struct {
ReadBufferLen int
InURL string
InModel string
InCount int
InWaitCount int
InNoDelay bool
InRecvTimeo int
InRcvBuff int
InSndBuff int
InReusePort bool
}
// ProvideConfigIo returns service config
func ProvideConfigIo(name string, config *Config) ConfigIo {
c := ConfigIo{}
config.viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // .env notOK, env Ok
c.ReadBufferLen, _ = config.GetIntOrDefault(fmt.Sprintf("%s.in.bufferlen", name), defaultReadBufferLen)
c.InURL, _ = config.GetStringOrDefault(fmt.Sprintf("%s.in.url", name), defaultInUrl)
c.InModel, _ = config.GetStringOrDefault(fmt.Sprintf("%s.in.iomodel", name), defaultInIoModel)
c.InCount, _ = config.GetIntOrDefault(fmt.Sprintf("%s.in.count", name), defaultInCount)
c.InWaitCount, _ = config.GetIntOrDefault(fmt.Sprintf("%s.in.waitcount", name), defaultInWaitCount)
return c
}