Skip to content

Instantly share code, notes, and snippets.

@alex3305
Created August 28, 2014 19:24
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 alex3305/ae1db5e21b0fcbf141ee to your computer and use it in GitHub Desktop.
Save alex3305/ae1db5e21b0fcbf141ee to your computer and use it in GitHub Desktop.
Very, very simple REST controller in Go with Hello World and Kill switch
package main
import (
"github.com/bmizerany/pat"
"log"
"net/http"
"os"
)
func main() {
m := pat.New()
m.Get("/hello/:name", http.HandlerFunc(hello))
m.Get("/kill", http.HandlerFunc(kill))
http.Handle("/", m)
log.Println("Listening... Go to /kill to kill the application.")
http.ListenAndServe(":8080", nil)
}
func hello(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello " + r.URL.Query().Get(":name")))
}
func kill(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Killing server!!"))
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment