This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:go-best-practices/invalid-host-port-pair
Language: Go
Severity: Warning
Category: Best Practices
Description
The host:port pair is invalid. The HTTP server needs to use a valid pair of address and port.
Non-Compliant Code Examples
packagemainimport("net")funcmain(){// Good
http.ListenAndServe("localhost:8080",nil)http.ListenAndServe(":8080",nil)http.ListenAndServe(":http",nil)http.ListenAndServe("localhost:http",nil)http.ListenAndServe("my_server:8080",nil)http.ListenAndServe("",nil)// Defaults to ":http"
// Bad
http.ListenAndServe("localhost:8080/",nil)http.ListenAndServe("localhost",nil)// Good
http.ListenAndServeTLS("localhost:8443","cert.pem","key.pem",nil)http.ListenAndServeTLS(":8443","cert.pem","key.pem",nil)http.ListenAndServeTLS("localhost:https","cert.pem","key.pem",nil)http.ListenAndServeTLS("my_server:8443","cert.pem","key.pem",nil)http.ListenAndServeTLS("","cert.pem","key.pem",nil)// Defaults to ":https"
// Bad
http.ListenAndServeTLS("localhost:8443/","cert.pem","key.pem",nil)http.ListenAndServeTLS("localhost","cert.pem","key.pem",nil)}
1
2
rulesets:- go-best-practices # Rules to enforce Go best practices.