top
(README.md)
dpmartini
=========
[![GoDoc](https://godoc.org/github.com/deferpanic/dpmartini?status.svg)](https://godoc.org/github.com/deferpanic/dpmartini)

Example of using Martini web framework with Defer Panic client library.

Please note, that Classic Martini function creates Martini with default martini.Recovery and martini.Logger middleware.
Usually it looks like a piece of code below:

__typically__

```go
func main() {
	m := martini.Classic()

	m.Get("/", func() string {
		return "Hello world!"
	})

	m.RunOnAddr(":3000")
}
```

So please create empty Martini instance first, then adding necessary middleware:

__example__

```go
package main

import (
	"github.com/deferpanic/deferclient/deferstats"
	"github.com/deferpanic/dpmartini/middleware"
	"github.com/go-martini/martini"
	"time"
)

func main() {
	dps := deferstats.NewClient("z57z3xsEfpqxpr0dSte0auTBItWBYa1c")

	go dps.CaptureStats()

	m := martini.New()
	r := martini.NewRouter()

	r.Get("/panic", func() string {
		panic("There is no need for panic")
		return "Hello world!"
	})
	r.Get("/slow", func() string {
		time.Sleep(5 * time.Second)
		return "Hello world!"
	})
	r.Get("/fast", func() string {
		return "Hello world!"
	})

	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)

	m.Use(middleware.Wrapper(dps))

	m.RunOnAddr(":3000")
}
```

Imports 3 package(s) ΒΆ

  1. github.com/deferpanic/deferclient/deferstats
  2. github.com/deferpanic/dpmartini/middleware
  3. github.com/go-martini/martini