chore(healthy): disable proxy in healthy check (#457)
fixed: https://github.com/appleboy/gorush/issues/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
This commit is contained in:
		
							parent
							
								
									c5a41eda4c
								
							
						
					
					
						commit
						850509e77c
					
				
							
								
								
									
										16
									
								
								main.go
								
								
								
								
							
							
						
						
									
										16
									
								
								main.go
								
								
								
								
							| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue