Skip to content

Instantly share code, notes, and snippets.

@yvasiyarov
Created May 11, 2014 09:57
Show Gist options
  • Save yvasiyarov/a0f6afdedcde25fc00b6 to your computer and use it in GitHub Desktop.
Save yvasiyarov/a0f6afdedcde25fc00b6 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/gocraft/web"
"net/http"
)
type Context struct {
HelloCount int
}
func (c *Context) SayHello(rw web.ResponseWriter, req *web.Request) {
rw.Write([]byte("Hello world"))
}
func main() {
router := web.New(Context{}). // Create your router
Middleware(web.LoggerMiddleware). // Use some included middleware
Middleware(web.ShowErrorsMiddleware). // ...
Get("/", (*Context).SayHello) // Add a route
http.ListenAndServe("localhost:3000", router) // Start the server!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment