Skip to content

Instantly share code, notes, and snippets.

@madflojo
Created July 31, 2021 03:22
Show Gist options
  • Save madflojo/48acf7390fc6762262972957a88270b8 to your computer and use it in GitHub Desktop.
Save madflojo/48acf7390fc6762262972957a88270b8 to your computer and use it in GitHub Desktop.
httprouter Article - Basic HTTP Example (no router)
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