mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat(nightscout): add headers property
This commit is contained in:
parent
8be7e573ae
commit
659a57f013
|
@ -3,6 +3,7 @@ package segments
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
http2 "net/http"
|
||||
"time"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||
|
@ -20,7 +21,8 @@ type Nightscout struct {
|
|||
|
||||
const (
|
||||
// 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"
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ func TestNSSegment(t *testing.T) {
|
|||
props := properties.Map{
|
||||
properties.CacheTimeout: tc.CacheTimeout,
|
||||
URL: "FAKE",
|
||||
Headers: map[string]string{"Fake-Header": "xxxxx"},
|
||||
}
|
||||
|
||||
cache := &mock.MockedCache{}
|
||||
|
|
|
@ -4370,6 +4370,12 @@
|
|||
"title": "Http request timeout",
|
||||
"description": "Milliseconds to use for http request timeouts",
|
||||
"default": 500
|
||||
},
|
||||
"headers": {
|
||||
"type": "object",
|
||||
"title": "Headers",
|
||||
"description": "A key, value map of Headers to send with the request",
|
||||
"default": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,11 +57,12 @@ Or display in mmol/l (instead of the default mg/dl) with the following template:
|
|||
|
||||
## Properties
|
||||
|
||||
| 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 |
|
||||
| `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? |
|
||||
| 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 |
|
||||
| `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 |
|
||||
| `cache_timeout` | `int` | `5` | in minutes - how long do you want your numbers cached? |
|
||||
|
||||
:::info
|
||||
You can change the icons for trend, put the trend elsewhere, add text, however you like!
|
||||
|
|
Loading…
Reference in a new issue