mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Allow using env variables in monitor and bookmarks widget URLs
This commit is contained in:
parent
a1afdb0c63
commit
7f667e2d1c
@ -13,11 +13,11 @@ type bookmarksWidget struct {
|
|||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Color *hslColorField `yaml:"color"`
|
Color *hslColorField `yaml:"color"`
|
||||||
Links []struct {
|
Links []struct {
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
URL string `yaml:"url"`
|
URL optionalEnvField `yaml:"url"`
|
||||||
Icon customIconField `yaml:"icon"`
|
Icon customIconField `yaml:"icon"`
|
||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
HideArrow bool `yaml:"hide-arrow"`
|
HideArrow bool `yaml:"hide-arrow"`
|
||||||
} `yaml:"links"`
|
} `yaml:"links"`
|
||||||
} `yaml:"groups"`
|
} `yaml:"groups"`
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type monitorWidget struct {
|
|||||||
widgetBase `yaml:",inline"`
|
widgetBase `yaml:",inline"`
|
||||||
Sites []struct {
|
Sites []struct {
|
||||||
*SiteStatusRequest `yaml:",inline"`
|
*SiteStatusRequest `yaml:",inline"`
|
||||||
Status *SiteStatus `yaml:"-"`
|
Status *siteStatus `yaml:"-"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Icon customIconField `yaml:"icon"`
|
Icon customIconField `yaml:"icon"`
|
||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
@ -109,28 +109,28 @@ func statusCodeToStyle(status int, altStatusCodes []int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SiteStatusRequest struct {
|
type SiteStatusRequest struct {
|
||||||
URL string `yaml:"url"`
|
URL optionalEnvField `yaml:"url"`
|
||||||
CheckURL string `yaml:"check-url"`
|
CheckURL optionalEnvField `yaml:"check-url"`
|
||||||
AllowInsecure bool `yaml:"allow-insecure"`
|
AllowInsecure bool `yaml:"allow-insecure"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SiteStatus struct {
|
type siteStatus struct {
|
||||||
Code int
|
Code int
|
||||||
TimedOut bool
|
TimedOut bool
|
||||||
ResponseTime time.Duration
|
ResponseTime time.Duration
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (SiteStatus, error) {
|
func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (siteStatus, error) {
|
||||||
var url string
|
var url string
|
||||||
if statusRequest.CheckURL != "" {
|
if statusRequest.CheckURL.String() != "" {
|
||||||
url = statusRequest.CheckURL
|
url = statusRequest.CheckURL.String()
|
||||||
} else {
|
} else {
|
||||||
url = statusRequest.URL
|
url = statusRequest.URL.String()
|
||||||
}
|
}
|
||||||
request, err := http.NewRequest(http.MethodGet, url, nil)
|
request, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SiteStatus{
|
return siteStatus{
|
||||||
Error: err,
|
Error: err,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (SiteStatus, error) {
|
|||||||
response, err = defaultInsecureHTTPClient.Do(request)
|
response, err = defaultInsecureHTTPClient.Do(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
status := SiteStatus{ResponseTime: time.Since(requestSentAt)}
|
status := siteStatus{ResponseTime: time.Since(requestSentAt)}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, context.DeadlineExceeded) {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
@ -165,7 +165,7 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (SiteStatus, error) {
|
|||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchStatusForSites(requests []*SiteStatusRequest) ([]SiteStatus, error) {
|
func fetchStatusForSites(requests []*SiteStatusRequest) ([]siteStatus, error) {
|
||||||
job := newJob(fetchSiteStatusTask, requests).withWorkers(20)
|
job := newJob(fetchSiteStatusTask, requests).withWorkers(20)
|
||||||
results, _, err := workerPoolDo(job)
|
results, _, err := workerPoolDo(job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user