Set default header for User-Agent
This commit is contained in:
parent
f1dfde6891
commit
b58ce4acb3
2 changed files with 16 additions and 2 deletions
14
http.go
Normal file
14
http.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
// httpClient is a wrapper around the default http.Client
|
||||
// It is used to add default headers to the requests.
|
||||
type httpClient struct {
|
||||
*http.Client
|
||||
}
|
||||
|
||||
func (c *httpClient) Do(req *http.Request) (*http.Response, error) {
|
||||
req.Header.Set("User-Agent", "ntfy-alertmanger")
|
||||
return c.Client.Do(req)
|
||||
}
|
4
main.go
4
main.go
|
@ -25,7 +25,7 @@ type receiver struct {
|
|||
cfg *config
|
||||
logger *log.Logger
|
||||
cache *cache
|
||||
client *http.Client
|
||||
client *httpClient
|
||||
}
|
||||
|
||||
type payload struct {
|
||||
|
@ -391,7 +391,7 @@ func main() {
|
|||
logger.Errorf("config: %v", err)
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: time.Second * 3}
|
||||
client := &httpClient{&http.Client{Timeout: time.Second * 3}}
|
||||
|
||||
receiver := &receiver{cfg: cfg, logger: logger, cache: newCache(cfg.cache.Duration), client: client}
|
||||
|
||||
|
|
Loading…
Reference in a new issue