Ce produit n'est pas pris en charge pour le site Datadog que vous avez sélectionné. ().
Cette page n'est pas encore disponible en français. Nous travaillons sur sa traduction.
Si vous avez des questions ou des commentaires concernant 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

package main

import ("net")

func main(){
    // 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)
}

Compliant Code Examples

package main

import ("net/http")

func main(){
    // Safe: valid host:port pairs
    http.ListenAndServe("localhost:8080", nil)
    http.ListenAndServe(":8080", nil)
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Intégrations fluides. Essayez Datadog Code Security