mirror of
				https://github.com/therootcompany/golib.git
				synced 2025-11-03 23:02:49 +00:00 
			
		
		
		
	add golib/https
This commit is contained in:
		
							parent
							
								
									dccf1f108a
								
							
						
					
					
						commit
						5eb3592744
					
				
							
								
								
									
										9
									
								
								https/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								https/README.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
# https (as in secure)
 | 
			
		||||
 | 
			
		||||
This wrappers and helpers to supplement Go's built-in `net/http` with reasonable and safe defaults.
 | 
			
		||||
 | 
			
		||||
See
 | 
			
		||||
 | 
			
		||||
-   [The complete guide to Go net/http timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/)
 | 
			
		||||
-   [Standard net/http config will break your production environment](https://medium.com/@simonfrey/go-as-in-golang-standard-net-http-config-will-break-your-production-environment-1360871cb72b)
 | 
			
		||||
-   [Don’t use Go’s default HTTP client (in production)](https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779)
 | 
			
		||||
							
								
								
									
										22
									
								
								https/https.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								https/https.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
package https
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// NewHTTPClient creates a new http client with reasonable and safe defaults
 | 
			
		||||
func NewHTTPClient() *http.Client {
 | 
			
		||||
	transport := &http.Transport{
 | 
			
		||||
		Dial: (&net.Dialer{
 | 
			
		||||
			Timeout: 10 * time.Second,
 | 
			
		||||
		}).Dial,
 | 
			
		||||
		TLSHandshakeTimeout: 5 * time.Second,
 | 
			
		||||
	}
 | 
			
		||||
	client := &http.Client{
 | 
			
		||||
		Timeout:   time.Second * 5,
 | 
			
		||||
		Transport: transport,
 | 
			
		||||
	}
 | 
			
		||||
	return client
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user