Created
December 5, 2018 09:43
-
-
Save sonyarianto/a2cdf7f40e77ed44fe492c9cc1a2d306 to your computer and use it in GitHub Desktop.
Web routing with Goji mux
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" | |
"goji.io" | |
"goji.io/pat" | |
"net/http" | |
) | |
func home(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "This is the %s!", "homepage") | |
} | |
func hello(w http.ResponseWriter, r *http.Request) { | |
name := pat.Param(r, "name") | |
fmt.Fprintf(w, "Hello, %s!", name) | |
} | |
func main() { | |
mux := goji.NewMux() | |
mux.HandleFunc(pat.Get("/"), home) | |
mux.HandleFunc(pat.Get("/hello/:name"), hello) | |
http.ListenAndServe("localhost:3000", mux) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment