resolved meta conundrum

This commit is contained in:
Annika Hannig 2021-10-27 14:24:07 +00:00
parent 783dd623e3
commit 982107dbc2
No known key found for this signature in database
GPG Key ID: 62E226E47DDCE58D
4 changed files with 11 additions and 18 deletions

View File

@ -73,11 +73,6 @@ type Rpki struct {
Invalid []string `json:"invalid"`
}
// A BackendResponse contains meta information.
type BackendResponse struct {
Meta Meta `json:"api"`
}
// Meta contains response meta information
// like cacheing time and cache ttl or the API version
type Meta struct {
@ -106,8 +101,8 @@ type Status struct {
// StatusResponse ??
type StatusResponse struct {
BackendResponse
Status Status `json:"status"`
Meta *Meta `json:"api"`
}
// A RouteServer is a datasource with attributes.

View File

@ -89,8 +89,8 @@ func (n *Neighbor) MatchName(name string) bool {
// A NeighborsResponse is a list of neighbors with
// caching information.
type NeighborsResponse struct {
BackendResponse
Neighbors Neighbors `json:"neighbors"`
Meta *Meta `json:"api"`
}
// CacheTTL returns the duration of validity
@ -130,6 +130,6 @@ func (neighbors NeighborsStatus) Swap(i, j int) {
// NeighborsStatusResponse contains the status of all neighbors
// on a RS.
type NeighborsStatusResponse struct {
BackendResponse
Neighbors NeighborsStatus `json:"neighbors"`
Meta *Meta `json:"api"`
}

View File

@ -69,7 +69,7 @@ func (routes Routes) Swap(i, j int) {
// RoutesResponse contains all routes from a source
type RoutesResponse struct {
BackendResponse
Meta *Meta `json:api`
Imported Routes `json:"imported"`
Filtered Routes `json:"filtered"`
NotExported Routes `json:"not_exported"`
@ -78,7 +78,7 @@ type RoutesResponse struct {
// CacheTTL returns the cache ttl of the reponse
func (res *RoutesResponse) CacheTTL() time.Duration {
now := time.Now().UTC()
return res.BackendResponse.Meta.TTL.Sub(now)
return res.Meta.TTL.Sub(now)
}
// Timed responses include the duration of the request
@ -161,11 +161,11 @@ func (r LookupRoutes) Swap(i, j int) {
// a set of lookup routes, as the result of a query of
// a specific route server.
type RoutesLookupResponse struct {
Response
Paginated
Timed
Searchable
Routes LookupRoutes `json:"routes"`
Meta *Meta `json:"api"`
}
// GlobalRoutesLookupResponse is the result of a routes

View File

@ -10,13 +10,11 @@ func TestStatusResponseSerialization(t *testing.T) {
// Make status
response := StatusResponse{
Response: Response{
Meta: Meta{
Version: "2.0.0",
CacheStatus: CacheStatus{},
ResultFromCache: false,
TTL: time.Now(),
},
Meta: &Meta{
Version: "2.0.0",
CacheStatus: CacheStatus{},
ResultFromCache: false,
TTL: time.Now(),
},
Status: Status{
Message: "Server is up and running",