Skip to content

Instantly share code, notes, and snippets.

@sonyarianto
Created December 5, 2018 09:43
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 sonyarianto/a2cdf7f40e77ed44fe492c9cc1a2d306 to your computer and use it in GitHub Desktop.
Save sonyarianto/a2cdf7f40e77ed44fe492c9cc1a2d306 to your computer and use it in GitHub Desktop.
Web routing with Goji mux
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