Skip to content

Instantly share code, notes, and snippets.

@steevehook
Created October 22, 2019 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/3e21392485acfed29ff58ca557a8d4ac to your computer and use it in GitHub Desktop.
Save steevehook/3e21392485acfed29ff58ca557a8d4ac to your computer and use it in GitHub Desktop.
module github.com/gophertuts/go-basics/packages/go-get
go 1.12
require github.com/julienschmidt/httprouter v1.3.0
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
func main() {
router := httprouter.New()
router.GET("/", func(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
// handle errors bastard
_, _ = fmt.Fprintf(w, "Welcome!")
})
router.GET("/people/:name", func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
name := ps.ByName("name")
// handle errors bastard
_, _ = fmt.Fprintf(w, "Welcome %s", name)
})
log.Fatal(http.ListenAndServe(":8080", router))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment