Created
October 22, 2019 15:25
-
-
Save steevehook/3e21392485acfed29ff58ca557a8d4ac to your computer and use it in GitHub Desktop.
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
| module github.com/gophertuts/go-basics/packages/go-get | |
| go 1.12 | |
| require github.com/julienschmidt/httprouter v1.3.0 |
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" | |
| "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