telebit/relay/api/server.go

39 lines
1.1 KiB
Go
Raw Normal View History

2020-05-01 05:47:46 +00:00
package api
2020-05-01 05:47:46 +00:00
import (
"time"
)
//ServerAPI -- Structure to support the server API
type ServerAPI struct {
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"`
}
//NewServerAPI - Constructor
func NewServerAPI(c *Connection) (s *ServerAPI) {
s = new(ServerAPI)
s.ServerName = c.ServerName()
s.ServerID = c.ConnectionID()
s.Domains = make([]*ServerDomainAPI, 0)
s.Duration = time.Since(c.ConnectTime()).Seconds()
s.Idle = time.Since(c.LastUpdate()).Seconds()
s.BytesIn = c.BytesIn()
s.BytesOut = c.BytesOut()
2020-05-01 05:47:46 +00:00
s.Source = c.Source()
2017-03-14 01:22:44 +00:00
for domainName := range c.DomainTrack {
domainAPI := NewServerDomainAPI(c, c.DomainTrack[domainName])
2017-03-14 01:22:44 +00:00
s.Domains = append(s.Domains, domainAPI)
}
return
}