Created
July 31, 2021 03:22
-
-
Save madflojo/48acf7390fc6762262972957a88270b8 to your computer and use it in GitHub Desktop.
httprouter Article - Basic HTTP Example (no router)
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" | |
"log" | |
"net/http" | |
) | |
// handler is a basic HTTP handler that prints hello world. | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello World") | |
} | |
func main() { | |
// Register our handler function | |
http.HandleFunc("/hello", handler) | |
// Start HTTP Listener | |
err := http.ListenAndServe(":8080", nil) | |
if err != nil { | |
log.Printf("HTTP Server stopped - %s", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment