Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Mongrel2 Handler for Go

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 README.rst
Octocat-spinner-32 m2go.go
Octocat-spinner-32 m2go_test.go
Octocat-spinner-32 request.go
Octocat-spinner-32 tnet.go
Octocat-spinner-32 tnet_bench.go
Octocat-spinner-32 tnet_test.go

m2go, a Mongrel2 http server for go.

Includes adapter to run Pat.go


Example App:

import (

func main() {
        log.SetFlags(log.Ltime | log.Lshortfile)
        m := pat.New()
        m.Get("/hello/:name", http.HandlerFunc(hello))
        m.Get("/stream", http.HandlerFunc(stream))
        m2go.ListenAndServe("tcp://|tcp://|d9eae9a0-6bad-11e1-9cc3-5254004a61b5", m)

func hello(w http.ResponseWriter, r *http.Request) {
        name := r.URL.Query().Get(":name")
        io.WriteString(w, "Hello, "+name)

// this will serve as a Streaming API, continuing to push out updates
// to connected client
func stream(w http.ResponseWriter, r *http.Request) {
        // this line:  is the key to make it streaming.
        r.Header.Set("Transfer-Encoding", "chunked")
        r.Header.Set("Content-Type", "application/json")
        io.WriteString(w, "some content")

        // lets simulate a zeromq type connection that recieves messages periocically
        //  and pushes to client
        timer := time.NewTicker(time.Second * 1)

        go func() {
                for _ = range timer.C {
                        io.WriteString(w, `{"msg":"still alive","status":200}`)
Something went wrong with that request. Please try again.