Skip to content

Commit

Permalink
chore(healthy): disable proxy in healthy check (#457)
Browse files Browse the repository at this point in the history
fixed: #456

Don’t use Go’s default HTTP client (in production)

ref: https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
  • Loading branch information
appleboy authored Jan 25, 2020
1 parent c5a41ed commit 850509e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"time"

"github.com/appleboy/gorush/config"
"github.com/appleboy/gorush/gorush"
Expand Down Expand Up @@ -291,12 +293,22 @@ func usage() {
// handles pinging the endpoint and returns an error if the
// agent is in an unhealthy state.
func pinger() error {
resp, err := http.Get("http://localhost:" + gorush.PushConf.Core.Port + gorush.PushConf.API.HealthURI)
var transport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
}
var client = &http.Client{
Timeout: time.Second * 10,
Transport: transport,
}
resp, err := client.Get("http://localhost:" + gorush.PushConf.Core.Port + gorush.PushConf.API.HealthURI)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("server returned non-200 status code")
}
return nil
Expand Down

0 comments on commit 850509e

Please sign in to comment.