Skip to content

club-codoon/martini-graceful

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graceful

wercker status

graceful shutdown for martini

API References

Usage

This package provides graceful shutdown to the martini application.

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:

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

About

graceful shutdown for martini

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%