Skip to content

Instantly share code, notes, and snippets.

@madalinignisca
Created February 19, 2024 15:17
Show Gist options
  • Save madalinignisca/b6c40e96bd5bbe341c1070067eaa839c to your computer and use it in GitHub Desktop.
Save madalinignisca/b6c40e96bd5bbe341c1070067eaa839c to your computer and use it in GitHub Desktop.
GO net/http tips
package main
import (
"fmt"
"net/http"
)
func helloWorld(w http.ResponseWriter, r *http.Request) {
// this is what you want
if r.URL.Path != "/" {
// I wonder if there's more about this...
http.NotFound(w, r) // Respond with a 404 Not Found
return
}
fmt.Fprintln(w, "Hello, World!")
}
func main() {
http.HandleFunc("/", helloWorld)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment