mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// Neighbours
|
|
type Neighbours []*Neighbour
|
|
|
|
type Neighbour struct {
|
|
Id string `json:"id"`
|
|
|
|
// Mandatory fields
|
|
Address string `json:"address"`
|
|
Asn int `json:"asn"`
|
|
State string `json:"state"`
|
|
Description string `json:"description"`
|
|
RoutesReceived int `json:"routes_received"`
|
|
RoutesFiltered int `json:"routes_filtered"`
|
|
RoutesExported int `json:"routes_exported"`
|
|
RoutesPreferred int `json:"routes_preferred"`
|
|
RoutesAccepted int `json:"routes_accepted"`
|
|
Uptime time.Duration `json:"uptime"`
|
|
LastError string `json:"last_error"`
|
|
|
|
// Original response
|
|
Details map[string]interface{} `json:"details"`
|
|
}
|
|
|
|
// Implement sorting interface for routes
|
|
func (neighbours Neighbours) Len() int {
|
|
return len(neighbours)
|
|
}
|
|
|
|
func (neighbours Neighbours) Less(i, j int) bool {
|
|
return neighbours[i].Asn < neighbours[j].Asn
|
|
}
|
|
|
|
func (neighbours Neighbours) Swap(i, j int) {
|
|
neighbours[i], neighbours[j] = neighbours[j], neighbours[i]
|
|
}
|
|
|
|
type NeighboursResponse struct {
|
|
Api ApiStatus `json:"api"`
|
|
Neighbours Neighbours `json:"neighbours"`
|
|
}
|
|
|
|
// Neighbours response is cacheable
|
|
func (self *NeighboursResponse) CacheTtl() time.Duration {
|
|
now := time.Now().UTC()
|
|
return self.Api.Ttl.Sub(now)
|
|
}
|
|
|
|
type NeighboursLookupResults map[string]Neighbours
|