graceful

package module
v0.0.0-...-f2d8dc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2014 License: MIT Imports: 6 Imported by: 0

README

# Graceful

[![wercker status](https://app.wercker.com/status/9b892bd85ba1b762b3f8d087e918f68b/s/master "wercker status")](https://app.wercker.com/project/bykey/9b892bd85ba1b762b3f8d087e918f68b)

graceful shutdown for martini

[API References](http://godoc.org/github.com/rosylilly/martini-graceful)

## Usage

This package provides graceful shutdown to the martini application.

```go
package main

import (
  "github.com/go-martini/martini"
  "github.com/rosylilly/martini-graceful"
  "log"
  "syscall"
  "time"
)

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

  gs := graceful.New(10 * time.Second, syscall.SIGTERM, syscall.SIGINT)
  m.Use(gs.Handler)

  m.Get("/", func() string {
    time.Sleep(5 * time.Second)
    return "hello world\n"
  })

  err := gs.RunGracefully(m)
  if err != nil {
    log.Println(err)
  }
}
```

Or:

```go
package main

import (
  "github.com/go-martini/martini"
  "github.com/rosylilly/martini-graceful"
  "log"
  "syscall"
  "time"
)

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

  gs := graceful.New(10 * time.Second, syscall.SIGTERM, syscall.SIGINT)
  m.Use(gs.Handler)

  m.Get("/", func() string {
    time.Sleep(5 * time.Second)
    return "hello world\n"
  })

  go func() {
    m.RunOnAddr(":8080")
  }()

  err := gs.Wait()
  if err != nil {
    log.Println(err)
  }
}
```

## License

MIT Lisence

## Authors

- [Sho Kusano / @rosylilly](https://github.com/rosylilly) <rosylilly@aduca.org>

Documentation

Overview

Package graceful provides graceful shutdown to the martini application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runnable

type Runnable interface {
	Run()
}

type Shutdown

type Shutdown struct {
	// contains filtered or unexported fields
}

func New

func New(timeoutDuration time.Duration, signals ...os.Signal) *Shutdown

func (*Shutdown) Handler

func (s *Shutdown) Handler(c martini.Context)

func (*Shutdown) RunGracefully

func (s *Shutdown) RunGracefully(m Runnable) error

func (*Shutdown) Wait

func (s *Shutdown) Wait() error

func (*Shutdown) WaitForRequests

func (s *Shutdown) WaitForRequests() <-chan error

func (*Shutdown) WaitForSignals

func (s *Shutdown) WaitForSignals() chan os.Signal

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL