telebit/rvpn/admin/server_api.go

47 lines
1.1 KiB
Go
Raw Normal View History

package admin
import (
"fmt"
"time"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/connection"
)
//ServerAPI -- Structure to support the server API
type ServerAPI struct {
2017-02-18 21:21:36 +00:00
ServerName string `json:"server_name"`
Domains []*DomainAPI `json:"domains"`
Duration float64 `json:"duration"`
BytesIn int64 `json:"bytes_in"`
BytesOut int64 `json:"bytes_out"`
}
//NewServerAPI - Constructor
func NewServerAPI(c *connection.Connection) (s *ServerAPI) {
s = new(ServerAPI)
s.ServerName = fmt.Sprintf("%p", c)
s.Domains = make([]*DomainAPI, 0)
s.Duration = time.Since(c.ConnectTime()).Seconds()
s.BytesIn = c.BytesIn()
s.BytesOut = c.BytesOut()
for d := range c.DomainTrack {
dt := c.DomainTrack[d]
domainAPI := NewDomainAPI(dt.DomainName, dt.BytesIn(), dt.BytesOut())
s.Domains = append(s.Domains, domainAPI)
}
return
}
//ServerAPIContainer -- Holder for all the Servers
type ServerAPIContainer struct {
2017-02-18 21:21:36 +00:00
Servers []*ServerAPI `json:"servers"`
}
//NewServerAPIContainer -- Constructor
func NewServerAPIContainer() (p *ServerAPIContainer) {
p = new(ServerAPIContainer)
p.Servers = make([]*ServerAPI, 0)
return p
}