2017-04-01 04:19:50 +00:00
|
|
|
package server
|
2017-02-16 02:06:26 +00:00
|
|
|
|
2017-03-25 22:22:28 +00:00
|
|
|
import "time"
|
2017-02-16 02:06:26 +00:00
|
|
|
|
|
|
|
//ServerAPI -- Structure to support the server API
|
|
|
|
type ServerAPI 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"`
|
|
|
|
Source string `json:"source_address"`
|
|
|
|
State bool `json:"server_state"`
|
2017-02-16 02:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewServerAPI - Constructor
|
2017-03-03 00:47:59 +00:00
|
|
|
func NewServerAPI(c *Connection) (s *ServerAPI) {
|
2017-02-16 02:06:26 +00:00
|
|
|
s = new(ServerAPI)
|
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()
|
2017-03-13 21:46:11 +00:00
|
|
|
s.Source = c.source
|
2017-02-16 02:06:26 +00:00
|
|
|
|
2017-03-14 01:22:44 +00:00
|
|
|
for domainName := range c.DomainTrack {
|
|
|
|
|
2017-03-26 01:33:09 +00:00
|
|
|
domainAPI := NewServerDomainAPI(c, c.DomainTrack[domainName])
|
2017-03-14 01:22:44 +00:00
|
|
|
s.Domains = append(s.Domains, domainAPI)
|
|
|
|
}
|
2017-02-16 02:06:26 +00:00
|
|
|
return
|
|
|
|
}
|