mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
include cache status from API
This commit is contained in:
@ -53,6 +53,7 @@ func parseApiStatus(bird ClientResponse, config Config) (api.ApiStatus, error) {
|
|||||||
return status, fmt.Errorf(birdErr)
|
return status, fmt.Errorf(birdErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse TTL
|
||||||
ttl, err := parseServerTime(
|
ttl, err := parseServerTime(
|
||||||
bird["ttl"],
|
bird["ttl"],
|
||||||
config.ServerTime,
|
config.ServerTime,
|
||||||
@ -62,10 +63,42 @@ func parseApiStatus(bird ClientResponse, config Config) (api.ApiStatus, error) {
|
|||||||
return api.ApiStatus{}, err
|
return api.ApiStatus{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse Cache Status
|
||||||
|
cacheStatus, err := parseCacheStatus(birdApi, config)
|
||||||
|
if err != nil {
|
||||||
|
return api.ApiStatus{}, err
|
||||||
|
}
|
||||||
|
|
||||||
status := api.ApiStatus{
|
status := api.ApiStatus{
|
||||||
Version: birdApi["Version"].(string),
|
Version: birdApi["Version"].(string),
|
||||||
ResultFromCache: birdApi["result_from_cache"].(bool),
|
ResultFromCache: birdApi["result_from_cache"].(bool),
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
|
CacheStatus: cacheStatus,
|
||||||
|
}
|
||||||
|
|
||||||
|
return status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse cache status from api response
|
||||||
|
func parseCacheStatus(cacheStatus map[string]interface{}, config Config) (api.CacheStatus, error) {
|
||||||
|
cache, ok := cacheStatus["cache_status"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return api.CacheStatus{}, fmt.Errorf("Invalid Cache Status")
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedAt, ok := cache["cached_at"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return api.CacheStatus{}, fmt.Errorf("Invalid Cache Status")
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedAtTime, err := parseServerTime(cachedAt["date"], config.ServerTime, config.Timezone)
|
||||||
|
if err != nil {
|
||||||
|
return api.CacheStatus{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
status := api.CacheStatus{
|
||||||
|
CachedAt: cachedAtTime,
|
||||||
|
// We ommit OrigTTL for now...
|
||||||
}
|
}
|
||||||
|
|
||||||
return status, nil
|
return status, nil
|
||||||
|
Reference in New Issue
Block a user