Guides

Request Handler

A sample request handler in Golf can be defined as following:

func mainHandler(ctx *golf.Context) {
    ctx.Send("Hello World")
}

When a request matching the routes of mainHandler comes into the server, Golf will build the request into a golf.Context instance, and pass the context into the related request handler.

In the above example, we used the method ctx.Write to respond the request with a string. For more methods available under Context, please take a look at the API for Context.