-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhost.go
161 lines (129 loc) · 3.33 KB
/
host.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package proxysql
// this file is for the host struct and functions on it
import (
"fmt"
)
// Host represents a row in ProxySQL's mysql_servers config table
type Host struct {
hostgroup_id int
hostname string
port int
status string
weight int
compression int
max_connections int
max_replication_lag int
use_ssl int
max_latency_ms int
comment string
}
// DefaultHost returns a default host (in terms of the mysql_servers table).
// Note that hostname is left empty
func DefaultHost() *Host {
return &Host{
0, // hostgroup_id
"", // hostname
3306, // port
"ONLINE", // status
1, // weight
0, // compression
1000, // max_connections
0, // max_replication_lag
0, // use_ssl
0, // max_latency_ms
"", // comment
}
}
// Setters for Host struct
func (h *Host) SetHostname(hn string) *Host {
h.hostname = hn
return h
}
func (h *Host) SetPort(p int) *Host {
h.port = p
return h
}
func (h *Host) SetHostgroupID(hg int) *Host {
h.hostgroup_id = hg
return h
}
func (h *Host) SetStatus(s string) *Host {
h.status = s
return h
}
func (h *Host) SetWeight(w int) *Host {
h.weight = w
return h
}
func (h *Host) SetCompression(c int) *Host {
h.compression = c
return h
}
func (h *Host) SetMaxConnections(m int) *Host {
h.max_connections = m
return h
}
func (h *Host) SetMaxReplicationLag(m int) *Host {
h.max_replication_lag = m
return h
}
func (h *Host) SetUseSSL(u int) *Host {
h.use_ssl = u
return h
}
func (h *Host) SetMaxLatencyMS(m int) *Host {
h.max_latency_ms = m
return h
}
func (h *Host) SetComment(c string) *Host {
h.comment = c
return h
}
// Builders for Host struct
func (h *Host) Hostname() string {
return h.hostname
}
func (h *Host) Port() int {
return h.port
}
func (h *Host) HostgroupID() int {
return h.hostgroup_id
}
func (h *Host) Status() string {
return h.status
}
func (h *Host) Weight() int {
return h.weight
}
func (h *Host) Compression() int {
return h.compression
}
func (h *Host) MaxConnections() int {
return h.max_connections
}
func (h *Host) MaxReplicationLag() int {
return h.max_replication_lag
}
func (h *Host) UseSSL() int {
return h.use_ssl
}
func (h *Host) MaxLatencyMS() int {
return h.max_latency_ms
}
func (h *Host) Comment() string {
return h.comment
}
func (h *Host) Valid() error {
hq := defaultHostQuery()
hq.host = h
return validateHostQuery(hq)
}
func (h *Host) values() string {
return fmt.Sprintf("(%d, '%s', %d, '%s', %d, %d, %d, %d, %d, %d, '%s')", h.hostgroup_id, h.hostname, h.port, h.status, h.weight, h.compression, h.max_connections, h.max_replication_lag, h.use_ssl, h.max_latency_ms, h.comment)
}
func (h *Host) columns() string {
return "(hostgroup_id, hostname, port, status, weight, compression, max_connections, max_replication_lag, use_ssl, max_latency_ms, comment)"
}
func (h *Host) where() string {
return fmt.Sprintf("hostgroup_id = %d and hostname = '%s' and port = %d and status = '%s' and weight = %d and compression = %d and max_connections = %d and max_replication_lag = %d and use_ssl = %d and max_latency_ms = %d and comment = '%s'", h.hostgroup_id, h.hostname, h.port, h.status, h.weight, h.compression, h.max_connections, h.max_replication_lag, h.use_ssl, h.max_latency_ms, h.comment)
}