/
options.go
66 lines (61 loc) · 1.45 KB
/
options.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
63
64
65
66
package emqd
import (
"crypto/md5"
"fmt"
"hash/crc32"
"io"
"os"
"time"
log "github.com/ericluj/elog"
"github.com/ericluj/emq/internal/common"
"github.com/ericluj/emq/internal/util"
)
type Options struct {
ID int64
TCPAddress string
HTTPAddress string
LookupdTCPAddresses []string
DataPath string
MemQueueSize int64
MinMsgSize int64
MaxMsgSize int64
MaxBytesPerFile int64
SyncEvery int64
SyncTimeout time.Duration
}
func NewOptions() *Options {
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("NewOptions: %v", err)
}
h := md5.New()
_, err = io.WriteString(h, hostname)
if err != nil {
log.Errorf("WriteString: %v", err)
}
defaultID := int64(crc32.ChecksumIEEE(h.Sum(nil)) % 1024)
o := &Options{
ID: defaultID,
TCPAddress: "0.0.0.0:6001",
HTTPAddress: "0.0.0.0:6002",
LookupdTCPAddresses: []string{
"127.0.0.1:7001",
},
DataPath: "./tmp",
MemQueueSize: 10000,
MinMsgSize: common.MinValidMsgLength,
MaxMsgSize: common.MinValidMsgLength + 1024*1024,
MaxBytesPerFile: 100 * 1024 * 1024,
SyncEvery: 2000,
SyncTimeout: 2 * time.Second,
}
if util.IsDocker() {
o.TCPAddress = fmt.Sprintf("%s:6001", util.GetDockerHost())
o.HTTPAddress = fmt.Sprintf("%s:6002", util.GetDockerHost())
o.LookupdTCPAddresses = []string{
"emqlookupd1:7001",
"emqlookupd2:7001",
}
}
return o
}