Created
February 19, 2024 15:17
-
-
Save madalinignisca/b6c40e96bd5bbe341c1070067eaa839c to your computer and use it in GitHub Desktop.
GO net/http tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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