2020-05-01 05:47:46 +00:00
|
|
|
package api
|
2017-02-16 02:06:26 +00:00
|
|
|
|
2020-05-01 05:47:46 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
)
|
2017-02-16 02:06:26 +00:00
|
|
|
|
2017-03-13 21:46:11 +00:00
|
|
|
//ServersAPI -- Structure to support the server API
|
|
|
|
type ServersAPI struct {
|
2017-03-26 01:33:09 +00:00
|
|
|
ServerName string `json:"server_name"`
|
|
|
|
ServerID int64 `json:"server_id"`
|
|
|
|
Domains []*ServerDomainAPI `json:"domains"`
|
|
|
|
Duration float64 `json:"duration"`
|
|
|
|
Idle float64 `json:"idle"`
|
|
|
|
BytesIn int64 `json:"bytes_in"`
|
|
|
|
BytesOut int64 `json:"bytes_out"`
|
|
|
|
Requests int64 `json:"requests"`
|
|
|
|
Responses int64 `json:"responses"`
|
|
|
|
Source string `json:"source_address"`
|
|
|
|
State bool `json:"server_state"`
|
2017-02-16 02:06:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 21:46:11 +00:00
|
|
|
//NewServersAPI - Constructor
|
|
|
|
func NewServersAPI(c *Connection) (s *ServersAPI) {
|
|
|
|
s = new(ServersAPI)
|
2017-03-25 22:22:28 +00:00
|
|
|
s.ServerName = c.ServerName()
|
2017-03-13 21:46:11 +00:00
|
|
|
s.ServerID = c.ConnectionID()
|
2017-03-26 01:33:09 +00:00
|
|
|
s.Domains = make([]*ServerDomainAPI, 0)
|
2017-02-16 02:06:26 +00:00
|
|
|
s.Duration = time.Since(c.ConnectTime()).Seconds()
|
2017-03-18 19:28:54 +00:00
|
|
|
s.Idle = time.Since(c.LastUpdate()).Seconds()
|
2017-02-16 02:06:26 +00:00
|
|
|
s.BytesIn = c.BytesIn()
|
|
|
|
s.BytesOut = c.BytesOut()
|
2020-05-01 05:47:46 +00:00
|
|
|
s.Requests = c.Requests
|
|
|
|
s.Responses = c.Responses
|
2017-03-13 21:46:11 +00:00
|
|
|
s.Source = c.Source()
|
2017-03-26 01:33:09 +00:00
|
|
|
s.State = c.State()
|
2017-02-16 02:06:26 +00:00
|
|
|
|
|
|
|
for d := range c.DomainTrack {
|
|
|
|
dt := c.DomainTrack[d]
|
2017-03-26 01:33:09 +00:00
|
|
|
domainAPI := NewServerDomainAPI(c, dt)
|
2017-02-16 02:06:26 +00:00
|
|
|
s.Domains = append(s.Domains, domainAPI)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//ServerAPIContainer -- Holder for all the Servers
|
|
|
|
type ServerAPIContainer struct {
|
2017-03-13 21:46:11 +00:00
|
|
|
Servers []*ServersAPI `json:"servers"`
|
2017-02-16 02:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewServerAPIContainer -- Constructor
|
|
|
|
func NewServerAPIContainer() (p *ServerAPIContainer) {
|
|
|
|
p = new(ServerAPIContainer)
|
2017-03-13 21:46:11 +00:00
|
|
|
p.Servers = make([]*ServersAPI, 0)
|
2017-02-16 02:06:26 +00:00
|
|
|
return p
|
|
|
|
}
|