mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix: cache_timeout mismatch + variable naming + schema.json
This commit is contained in:
parent
6097d2d357
commit
ba71a4a16d
|
@ -44,6 +44,8 @@ const (
|
||||||
HTTPTimeout Property = "http_timeout"
|
HTTPTimeout Property = "http_timeout"
|
||||||
// DefaultHTTPTimeout default timeout used when executing http request
|
// DefaultHTTPTimeout default timeout used when executing http request
|
||||||
DefaultHTTPTimeout = 20
|
DefaultHTTPTimeout = 20
|
||||||
|
// DefaultCacheTimeout default timeout used when caching data
|
||||||
|
DefaultCacheTimeout = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
func printConfigError(err error, eval bool) {
|
func printConfigError(err error, eval bool) {
|
||||||
|
|
|
@ -21,8 +21,10 @@ const (
|
||||||
LOCATION Property = "location"
|
LOCATION Property = "location"
|
||||||
// UNITS openweathermap units
|
// UNITS openweathermap units
|
||||||
UNITS Property = "units"
|
UNITS Property = "units"
|
||||||
// CACHETIMEOUT cache timeout
|
// CACHETimeout cache timeout
|
||||||
CACHETIMEOUT Property = "cachetimeout"
|
CACHETimeout Property = "cache_timeout"
|
||||||
|
// CACHEKey key used when caching the response
|
||||||
|
CACHEKey string = "owm_response"
|
||||||
)
|
)
|
||||||
|
|
||||||
type weather struct {
|
type weather struct {
|
||||||
|
@ -67,14 +69,14 @@ func (d *owm) getResult() (*OWMDataResponse, error) {
|
||||||
apikey := d.props.getString(APIKEY, ".")
|
apikey := d.props.getString(APIKEY, ".")
|
||||||
location := d.props.getString(LOCATION, "De Bilt,NL")
|
location := d.props.getString(LOCATION, "De Bilt,NL")
|
||||||
units := d.props.getString(UNITS, "standard")
|
units := d.props.getString(UNITS, "standard")
|
||||||
timeout := d.props.getInt(HTTPTimeout, DefaultHTTPTimeout)
|
httpTimeout := d.props.getInt(HTTPTimeout, DefaultHTTPTimeout)
|
||||||
cachetimeout := int64(d.props.getInt(CACHETIMEOUT, 10))
|
cacheTimeout := int64(d.props.getInt(CACHETimeout, DefaultCacheTimeout))
|
||||||
|
|
||||||
d.url = fmt.Sprintf("http://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s", location, units, apikey)
|
d.url = fmt.Sprintf("http://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s", location, units, apikey)
|
||||||
|
|
||||||
if cachetimeout > 0 {
|
if cacheTimeout > 0 {
|
||||||
// check if data stored in cache
|
// check if data stored in cache
|
||||||
val, found := d.env.cache().get("owm_response")
|
val, found := d.env.cache().get(CACHEKey)
|
||||||
// we got something from te cache
|
// we got something from te cache
|
||||||
if found {
|
if found {
|
||||||
q := new(OWMDataResponse)
|
q := new(OWMDataResponse)
|
||||||
|
@ -86,7 +88,7 @@ func (d *owm) getResult() (*OWMDataResponse, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := d.env.doGet(d.url, timeout)
|
body, err := d.env.doGet(d.url, httpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return new(OWMDataResponse), err
|
return new(OWMDataResponse), err
|
||||||
}
|
}
|
||||||
|
@ -96,9 +98,9 @@ func (d *owm) getResult() (*OWMDataResponse, error) {
|
||||||
return new(OWMDataResponse), err
|
return new(OWMDataResponse), err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cachetimeout > 0 {
|
if cacheTimeout > 0 {
|
||||||
// persist new forecasts in cache
|
// persist new forecasts in cache
|
||||||
d.env.cache().set("owm_response", string(body), cachetimeout)
|
d.env.cache().set(CACHEKey, string(body), cacheTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestOWMSegmentSingle(t *testing.T) {
|
||||||
APIKEY: "key",
|
APIKEY: "key",
|
||||||
LOCATION: "AMSTERDAM,NL",
|
LOCATION: "AMSTERDAM,NL",
|
||||||
UNITS: "metric",
|
UNITS: "metric",
|
||||||
CACHETIMEOUT: 0,
|
CACHETimeout: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ func TestOWMSegmentIcons(t *testing.T) {
|
||||||
APIKEY: "key",
|
APIKEY: "key",
|
||||||
LOCATION: "AMSTERDAM,NL",
|
LOCATION: "AMSTERDAM,NL",
|
||||||
UNITS: "metric",
|
UNITS: "metric",
|
||||||
CACHETIMEOUT: 0,
|
CACHETimeout: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1547,12 +1547,6 @@
|
||||||
},
|
},
|
||||||
"http_timeout": {
|
"http_timeout": {
|
||||||
"$ref": "#/definitions/http_timeout"
|
"$ref": "#/definitions/http_timeout"
|
||||||
},
|
|
||||||
"cache_timeout": {
|
|
||||||
"type": "integer",
|
|
||||||
"title": "cache timeout",
|
|
||||||
"description": "The number of minutes the response is cached. A value of 0 disables the cache.",
|
|
||||||
"default": 10
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1595,6 +1589,12 @@
|
||||||
},
|
},
|
||||||
"http_timeout": {
|
"http_timeout": {
|
||||||
"$ref": "#/definitions/http_timeout"
|
"$ref": "#/definitions/http_timeout"
|
||||||
|
},
|
||||||
|
"cache_timeout": {
|
||||||
|
"type": "integer",
|
||||||
|
"title": "cache timeout",
|
||||||
|
"description": "The number of minutes the response is cached. A value of 0 disables the cache.",
|
||||||
|
"default": 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue