/
backend.go
72 lines (62 loc) · 1.52 KB
/
backend.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
package core
/**
* backend.go - backend definition
*
* @author Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
*/
import (
"fmt"
)
/**
* Backend means upstream server
* with all needed associate information
*/
type Backend struct {
Target
Priority int `json:"priority"`
Weight int `json:"weight"`
Sni string `json:"sni,omitempty"`
Stats BackendStats `json:"stats"`
}
/**
* Backend status
*/
type BackendStats struct {
Live bool `json:"live"`
Discovered bool `json:"discovered"`
TotalConnections int64 `json:"total_connections"`
ActiveConnections uint `json:"active_connections"`
RefusedConnections uint64 `json:"refused_connections"`
RxBytes uint64 `json:"rx"`
TxBytes uint64 `json:"tx"`
RxSecond uint `json:"rx_second"`
TxSecond uint `json:"tx_second"`
}
/**
* Check if backend equal to another
*/
func (this *Backend) EqualTo(other Backend) bool {
return this.Target.EqualTo(other.Target)
}
/**
* Merge another backend to this one
*/
func (this *Backend) MergeFrom(other Backend) *Backend {
this.Priority = other.Priority
this.Weight = other.Weight
this.Sni = other.Sni
return this
}
/**
* Get backends target address
*/
func (this *Backend) Address() string {
return this.Target.Address()
}
/**
* String conversion
*/
func (this Backend) String() string {
return fmt.Sprintf("{%s p=%d,w=%d,l=%t,a=%d}",
this.Address(), this.Priority, this.Weight, this.Stats.Live, this.Stats.ActiveConnections)
}