Add url option to healthcheck command
This commit is contained in:
parent
9bd5c61782
commit
56a95d6c16
2 changed files with 29 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ package healthcheck
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -22,11 +23,26 @@ func NewCmd(traefikConfiguration *static.Configuration, loaders []cli.ResourceLo
|
|||
}
|
||||
}
|
||||
|
||||
func runCmd(traefikConfiguration *static.Configuration) func(_ []string) error {
|
||||
return func(_ []string) error {
|
||||
func runCmd(traefikConfiguration *static.Configuration) func(args []string) error {
|
||||
return func(args []string) error {
|
||||
fs := flag.NewFlagSet("healthcheck", flag.ContinueOnError)
|
||||
urlFlag := fs.String("url", "", "")
|
||||
fs.SetOutput(os.Stderr)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
traefikConfiguration.SetEffectiveConfiguration()
|
||||
|
||||
resp, errPing := Do(*traefikConfiguration)
|
||||
var resp *http.Response
|
||||
var errPing error
|
||||
if *urlFlag != "" {
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, errPing = client.Head(*urlFlag)
|
||||
} else {
|
||||
resp, errPing = Do(*traefikConfiguration)
|
||||
}
|
||||
|
||||
if resp != nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue