Skip to content

Instantly share code, notes, and snippets.

@chadlung
Created July 6, 2015 16:12
Show Gist options
  • Save chadlung/f17f64ec4d48c2271aae to your computer and use it in GitHub Desktop.
Save chadlung/f17f64ec4d48c2271aae to your computer and use it in GitHub Desktop.
Go: Simple, Easy, Fast - Building a Go (golang) REST Service with Gorilla - Step 1: http://www.giantflyingsaucer.com/blog/?p=5635
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/hello/{name}", index).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", router))
}
func index(w http.ResponseWriter, r *http.Request) {
log.Println("Responsing to /hello request")
log.Println(r.UserAgent())
vars := mux.Vars(r)
name := vars["name"]
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "Hello:", name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment