Adding support for Domain and Domains
This commit is contained in:
parent
dd7d63baf6
commit
3d5d272736
|
@ -0,0 +1,52 @@
|
|||
package genericlistener
|
||||
|
||||
//DomainsAPI -- Structure to support the server API
|
||||
type DomainsAPI struct {
|
||||
DomainName string `json:"domain_name"`
|
||||
ServerID int64 `json:"server_id"`
|
||||
BytesIn int64 `json:"bytes_in"`
|
||||
BytesOut int64 `json:"bytes_out"`
|
||||
}
|
||||
|
||||
//NewDomainsAPI - Constructor
|
||||
func NewDomainsAPI(c *Connection, d *DomainTrack) (s *DomainsAPI) {
|
||||
s = new(DomainsAPI)
|
||||
s.DomainName = d.DomainName
|
||||
s.ServerID = c.ConnectionID()
|
||||
s.BytesIn = d.BytesIn()
|
||||
s.BytesOut = d.BytesOut()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//DomainsAPIContainer -- Holder for all the Servers
|
||||
type DomainsAPIContainer struct {
|
||||
Domains []*DomainsAPI `json:"domains"`
|
||||
}
|
||||
|
||||
//NewDomainsAPIContainer -- Constructor
|
||||
func NewDomainsAPIContainer() (p *DomainsAPIContainer) {
|
||||
p = new(DomainsAPIContainer)
|
||||
p.Domains = make([]*DomainsAPI, 0)
|
||||
return p
|
||||
}
|
||||
|
||||
//DomainAPI -- Structure to support the server API
|
||||
type DomainAPI struct {
|
||||
DomainName string `json:"domain_name"`
|
||||
ServerID int64 `json:"server_id"`
|
||||
BytesIn int64 `json:"bytes_in"`
|
||||
BytesOut int64 `json:"bytes_out"`
|
||||
Source string `json:"source_addr"`
|
||||
}
|
||||
|
||||
//NewDomainsAPI - Constructor
|
||||
func NewDomainAPI(c *Connection, d *DomainTrack) (s *DomainAPI) {
|
||||
s = new(DomainAPI)
|
||||
s.DomainName = d.DomainName
|
||||
s.ServerID = c.ConnectionID()
|
||||
s.BytesIn = d.BytesIn()
|
||||
s.BytesOut = d.BytesOut()
|
||||
s.Source = c.Source()
|
||||
return
|
||||
}
|
|
@ -27,5 +27,10 @@ func NewServerAPI(c *Connection) (s *ServerAPI) {
|
|||
s.BytesOut = c.BytesOut()
|
||||
s.Source = c.source
|
||||
|
||||
for domainName := range c.DomainTrack {
|
||||
|
||||
domainAPI := NewDomainAPI(c, c.DomainTrack[domainName])
|
||||
s.Domains = append(s.Domains, domainAPI)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ func NewServersAPI(c *Connection) (s *ServersAPI) {
|
|||
|
||||
for d := range c.DomainTrack {
|
||||
dt := c.DomainTrack[d]
|
||||
domainAPI := NewDomainAPI(dt.DomainName, dt.BytesIn(), dt.BytesOut())
|
||||
domainAPI := NewDomainAPI(c, dt)
|
||||
s.Domains = append(s.Domains, domainAPI)
|
||||
}
|
||||
return
|
||||
|
|
|
@ -43,7 +43,9 @@ func handleAdminClient(ctx context.Context, oneConn *oneConnListener) {
|
|||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprintln(w, "<html>Welcome..press <a href=/api/com.daplie.rvpn/servers>Servers</a> to access stats</html>")
|
||||
})
|
||||
|
||||
router.HandleFunc(endPointPrefix+"domains", getDomainsEndpoint).Methods("GET")
|
||||
router.HandleFunc(endPointPrefix+"domain/", getDomainEndpoint).Methods("GET")
|
||||
router.HandleFunc(endPointPrefix+"domain/{domain-name}", getDomainEndpoint).Methods("GET")
|
||||
router.HandleFunc(endPointPrefix+"servers", getServersEndpoint).Methods("GET")
|
||||
router.HandleFunc(endPointPrefix+"server/", getServerEndpoint).Methods("GET")
|
||||
router.HandleFunc(endPointPrefix+"server/{server-id}", getServerEndpoint).Methods("GET")
|
||||
|
@ -65,6 +67,54 @@ func handleAdminClient(ctx context.Context, oneConn *oneConnListener) {
|
|||
}
|
||||
}
|
||||
|
||||
func getDomainsEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
domainsContainer := NewDomainsAPIContainer()
|
||||
|
||||
for domain := range connectionTable.domains {
|
||||
conn := connectionTable.domains[domain]
|
||||
domainAPI := NewDomainsAPI(conn, conn.DomainTrack[domain])
|
||||
domainsContainer.Domains = append(domainsContainer.Domains, domainAPI)
|
||||
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
|
||||
env := envelope.NewEnvelope("domains/GET")
|
||||
env.Result = domainsContainer
|
||||
env.GenerateWriter(w)
|
||||
|
||||
}
|
||||
|
||||
func getDomainEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
env := envelope.NewEnvelope("domain/GET")
|
||||
|
||||
params := mux.Vars(r)
|
||||
if id, ok := params["domain-name"]; !ok {
|
||||
env.Error = "domain-name is missing"
|
||||
env.ErrorURI = r.RequestURI
|
||||
env.ErrorDescription = "domain API requires a domain-name"
|
||||
} else {
|
||||
domainName := id
|
||||
if conn, ok := connectionTable.domains[domainName]; !ok {
|
||||
env.Error = "domain-name was not found"
|
||||
env.ErrorURI = r.RequestURI
|
||||
env.ErrorDescription = "domain-name not found"
|
||||
} else {
|
||||
|
||||
domainAPI := NewDomainAPI(conn, conn.DomainTrack[domainName])
|
||||
env.Result = domainAPI
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
env.GenerateWriter(w)
|
||||
}
|
||||
|
||||
func getServersEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
@ -82,9 +132,6 @@ func getServersEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
env := envelope.NewEnvelope("servers/GET")
|
||||
env.Result = serverContainer
|
||||
env.GenerateWriter(w)
|
||||
|
||||
//json.NewEncoder(w).Encode(serverContainer)
|
||||
|
||||
}
|
||||
|
||||
func getServerEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package genericlistener
|
||||
|
||||
//DomainAPI -- Structure to hold the domain tracking for JSON
|
||||
type DomainAPI struct {
|
||||
Domain string `json:"domain"`
|
||||
BytesIn int64 `json:"bytes_in"`
|
||||
BytesOut int64 `json:"bytes_out"`
|
||||
}
|
||||
// type DomainAPI struct {
|
||||
// Domain string `json:"domain"`
|
||||
// BytesIn int64 `json:"bytes_in"`
|
||||
// BytesOut int64 `json:"bytes_out"`
|
||||
// }
|
||||
|
||||
//NewDomainAPI - Constructor
|
||||
func NewDomainAPI(domain string, bytesin int64, bytesout int64) (d *DomainAPI) {
|
||||
d = new(DomainAPI)
|
||||
d.Domain = domain
|
||||
d.BytesIn = bytesin
|
||||
d.BytesOut = bytesout
|
||||
return
|
||||
}
|
||||
// //NewDomainAPI - Constructor
|
||||
// func NewDomainAPI(domain string, bytesin int64, bytesout int64) (d *DomainAPI) {
|
||||
// d = new(DomainAPI)
|
||||
// d.Domain = domain
|
||||
// d.BytesIn = bytesin
|
||||
// d.BytesOut = bytesout
|
||||
// return
|
||||
// }
|
||||
|
||||
// //DomainAPIContainer --
|
||||
// type DomainAPIContainer struct {
|
||||
|
|
Loading…
Reference in New Issue