Skip to content

Instantly share code, notes, and snippets.

@madflojo
Created July 31, 2021 03:52
Show Gist options
  • Save madflojo/78e999d855769d734bfcec1908ab7aa8 to your computer and use it in GitHub Desktop.
Save madflojo/78e999d855769d734bfcec1908ab7aa8 to your computer and use it in GitHub Desktop.
httprouter Article - Basic HTTP Example (w/httprouter)
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
// handler is a basic HTTP handler that prints hello world.
func handler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "Hello World")
}
func main() {
// Create Router
router := httprouter.New()
router.GET("/hello", handler)
// Start HTTP Listener
err := http.ListenAndServe(":8080", router)
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