Created
July 6, 2015 16:12
-
-
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
This file contains 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/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