mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(nightscout): add headers property
This commit is contained in:
parent
8be7e573ae
commit
659a57f013
|
@ -3,6 +3,7 @@ package segments
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
http2 "net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||||
|
@ -21,6 +22,7 @@ type Nightscout struct {
|
||||||
const (
|
const (
|
||||||
// Your complete Nightscout URL and APIKey like this
|
// Your complete Nightscout URL and APIKey like this
|
||||||
URL properties.Property = "url"
|
URL properties.Property = "url"
|
||||||
|
Headers properties.Property = "headers"
|
||||||
|
|
||||||
DoubleUpIcon properties.Property = "doubleup_icon"
|
DoubleUpIcon properties.Property = "doubleup_icon"
|
||||||
SingleUpIcon properties.Property = "singleup_icon"
|
SingleUpIcon properties.Property = "singleup_icon"
|
||||||
|
@ -116,7 +118,14 @@ func (ns *Nightscout) getResult() (*NightscoutData, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ns.env.HTTPRequest(url, nil, httpTimeout)
|
headers := ns.props.GetKeyValueMap(Headers, map[string]string{})
|
||||||
|
modifiers := func(request *http2.Request) {
|
||||||
|
for key, value := range headers {
|
||||||
|
request.Header.Add(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := ns.env.HTTPRequest(url, nil, httpTimeout, modifiers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,7 @@ func TestNSSegment(t *testing.T) {
|
||||||
props := properties.Map{
|
props := properties.Map{
|
||||||
properties.CacheTimeout: tc.CacheTimeout,
|
properties.CacheTimeout: tc.CacheTimeout,
|
||||||
URL: "FAKE",
|
URL: "FAKE",
|
||||||
|
Headers: map[string]string{"Fake-Header": "xxxxx"},
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := &mock.MockedCache{}
|
cache := &mock.MockedCache{}
|
||||||
|
|
|
@ -4370,6 +4370,12 @@
|
||||||
"title": "Http request timeout",
|
"title": "Http request timeout",
|
||||||
"description": "Milliseconds to use for http request timeouts",
|
"description": "Milliseconds to use for http request timeouts",
|
||||||
"default": 500
|
"default": 500
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"type": "object",
|
||||||
|
"title": "Headers",
|
||||||
|
"description": "A key, value map of Headers to send with the request",
|
||||||
|
"default": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,9 @@ Or display in mmol/l (instead of the default mg/dl) with the following template:
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --------------- | :------: | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------- | :-----------------: | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `url` | `string` | | Your Nightscout URL, including the full path to entries.json AND count=1 AND token. Example above. You'll know this works if you can curl it yourself and get a single value |
|
| `url` | `string` | | Your Nightscout URL, including the full path to entries.json AND count=1 AND token. Example above. You'll know this works if you can curl it yourself and get a single value |
|
||||||
|
| `headers` | `map[string]string` | | A key, value map of Headers to send with the request |
|
||||||
| `http_timeout` | `int` | `500` | in milliseconds - how long do you want to wait before you want to see your prompt more than your sugar? I figure a half second is a good default |
|
| `http_timeout` | `int` | `500` | in milliseconds - how long do you want to wait before you want to see your prompt more than your sugar? I figure a half second is a good default |
|
||||||
| `cache_timeout` | `int` | `5` | in minutes - how long do you want your numbers cached? |
|
| `cache_timeout` | `int` | `5` | in minutes - how long do you want your numbers cached? |
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue