-
Notifications
You must be signed in to change notification settings - Fork 43
/
config.go
114 lines (103 loc) · 2.72 KB
/
config.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package spec
import (
"fmt"
"github.com/urfave/cli"
"runtime"
)
type AMQPConfig struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
VirtualHost string `json:"virtual_host" yaml:"virtual_host"`
}
func NewDefaultAMQPConfig() *AMQPConfig {
return &AMQPConfig{
Host: "127.0.0.1",
Port: 5676,
Username: "palm-user",
Password: "awesome-palm-password",
VirtualHost: "palm",
}
}
func (a *AMQPConfig) GetAMQPUrl() string {
return fmt.Sprintf("amqp://%v:%v@%v:%v/%v",
a.Username, a.Password, a.Host, a.Port, a.VirtualHost,
)
}
type PostgresDBConfig struct {
DatabaseName string `json:"database_name" yaml:"database_name"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
}
func NewDefaultDatabaseConfig() *PostgresDBConfig {
return &PostgresDBConfig{
DatabaseName: "palm",
Host: "127.0.0.1",
Port: 5435,
Username: "palm-user",
Password: "awesome-palm",
}
}
func (p *PostgresDBConfig) GetPostgresParams() string {
return fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v sslmode=disable",
p.Host, p.Port, p.Username, p.DatabaseName, p.Password,
)
}
type AuditLogConfig struct {
ServerAddr string `json:"server_addr" yaml:"server_addr"`
PageSize int `json:"page_size" yaml:"page_size"`
FailReadMaxTicket int `json:"fail_read_max_ticket" yaml:"fail_read_max_ticket"`
}
func NewDefaultAuditLogConfig() *AuditLogConfig {
return &AuditLogConfig{
ServerAddr: "http://192.168.253.83:11001/access/query-by-type",
PageSize: 2000,
FailReadMaxTicket: 10,
}
}
func GetCliBasicConfig(idPrefix string) []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "server",
Value: "127.0.0.1",
},
cli.IntFlag{
Name: "mq-port",
Value: 5676,
},
cli.StringFlag{
Name: "mq-user",
Value: "palm-user",
},
cli.StringFlag{
Name: "mq-pass",
Value: "awesome-palm-password",
},
//cli.StringFlag{
// Name: "token",
// Value: "",
//},
cli.StringFlag{
Name: "id",
Usage: "NodeId",
Value: fmt.Sprintf("%s-[%s]", idPrefix, runtime.GOOS+runtime.GOARCH),
},
cli.StringFlag{
Name: "server-port",
Value: "8082",
Usage: "port of web api",
},
}
}
func LoadAMQPConfigFromCliContext(c *cli.Context) *AMQPConfig {
return &AMQPConfig{
Host: c.String("server"),
Port: c.Int("mq-port"),
Username: c.String("mq-user"),
Password: c.String("mq-pass"),
VirtualHost: "palm",
}
}