Resources for golang web development.
- render json
- render text
- set headers
- serve a file
- parse an url
- parse a json request
- nesting templates
- multipart-form processing
Introductory articles and tutorials
-
writing web applications - official golang tutorial
-
how i start - tutorial demonstrating how to setup a basic REST API
-
quick and clean - multi-part article walking through the creation of a guestbook app (here refactored to use bolt for persistence in place of mongo)
-
building your own web framework - very nice series of articles (in 5 parts) describing how to roll-your own custom framework with context-aware handler chains
-
recap of request handling - awesome overview ... and, in fact, all of Alex Edwards periodic posts on web development with Go are well worth a read
-
building web applications - free e-book covering the basics
Useful packages for creating and processing form data include:
How to share context and functionality
If you're using a middleware pattern to process HTTP requests in Go, you may want to share some data or context between middleware handlers and your application handlers.
-
painless web handlers - sharing context by creating a new
handler
type with aServeHTTP
method -
basic auth example - with
httprouter
-
example of decorating a handler and handlefunc with a db
-
example of wrapping your handlers with a closure for composiblity.
For material specifically focused on HTTP API / web service development, see this gist.
The gorilla web toolkit provides a fairly comprehensive set of web utility packages.
For basic routing, I like httprouter ... and, along similar lines, httptreemux.
Both gin-gonic and echo appear to be nice/performant micro-web frameworks.
Other stuff ...
- gin - live reloading
- negroni - bidirectional middleware flow
- render - improved templating
- sqlx - convenient extensions to
database/sql
- cors - CORS middleware
- goth - multi-provider authentication
- goji - a basic router providing request context
- gorilla/context - registry for global request variables
- go-form-it - easy form creation and handling
-
go constants - e.g.,
http.StatusOK
= 200