本文整理匯總了Golang中github.com/codegangsta/martini.Recovery函數的典型用法代碼示例。如果您正苦於以下問題:Golang Recovery函數的具體用法?Golang Recovery怎麽用?Golang Recovery使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Recovery函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Load DB
options := &bolt.Options{Timeout: 2 * time.Second}
dbPath := path.Join(os.Getenv("BOLT_PATH"), "reminder.db")
db, err := bolt.Open(dbPath, 0600, options)
if err != nil {
log.Fatalf("Error opening bolt DB: %v", err)
}
defer db.Close()
// Schedule all (non-cancelled) Reminders
rems, err := remind.GetAllReminders(db)
if err != nil {
log.Fatalf("Error getting reminders: %v\n", err)
}
runningReminders.Schedule(db, rems)
//
// Router, etc
//
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Action(r.Handle)
m.Map(db)
r.Post("/sms", incomingSMS)
m.Run()
}
示例2: main
func main() {
m := martini.New()
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(nrscstatic.NrscStatic("public", true))
http.ListenAndServe(":8080", m)
}
示例3: startGUI
func startGUI(cfg GUIConfiguration, m *Model) {
router := martini.NewRouter()
router.Get("/", getRoot)
router.Get("/rest/version", restGetVersion)
router.Get("/rest/model", restGetModel)
router.Get("/rest/connections", restGetConnections)
router.Get("/rest/config", restGetConfig)
router.Get("/rest/config/sync", restGetConfigInSync)
router.Get("/rest/system", restGetSystem)
router.Get("/rest/errors", restGetErrors)
router.Post("/rest/config", restPostConfig)
router.Post("/rest/restart", restPostRestart)
router.Post("/rest/reset", restPostReset)
router.Post("/rest/error", restPostError)
router.Post("/rest/error/clear", restClearErrors)
go func() {
mr := martini.New()
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
mr.Use(basic(cfg.User, cfg.Password))
}
mr.Use(embeddedStatic())
mr.Use(martini.Recovery())
mr.Use(restMiddleware)
mr.Action(router.Handle)
mr.Map(m)
err := http.ListenAndServe(cfg.Address, mr)
if err != nil {
warnln("GUI not possible:", err)
}
}()
}
示例4: startGUI
func startGUI(addr string, m *Model) {
router := martini.NewRouter()
router.Get("/", getRoot)
router.Get("/rest/version", restGetVersion)
router.Get("/rest/model", restGetModel)
router.Get("/rest/connections", restGetConnections)
router.Get("/rest/config", restGetConfig)
router.Get("/rest/config/sync", restGetConfigInSync)
router.Get("/rest/need", restGetNeed)
router.Get("/rest/system", restGetSystem)
router.Get("/rest/errors", restGetErrors)
router.Post("/rest/config", restPostConfig)
router.Post("/rest/restart", restPostRestart)
router.Post("/rest/error", restPostError)
go func() {
mr := martini.New()
mr.Use(embeddedStatic())
mr.Use(martini.Recovery())
mr.Action(router.Handle)
mr.Map(m)
err := http.ListenAndServe(addr, mr)
if err != nil {
warnln("GUI not possible:", err)
}
}()
}
示例5: NewServer
// NewServer creates an instance of a martini server. The
// adapterInst parameter is the adapter type the server will
// use when dispatching requests.
func NewServer(adapterInst PanamaxAdapter) AdapterServer {
s := martini.New()
// Setup middleware
s.Use(martini.Recovery())
s.Use(martini.Logger())
s.Use(mapEncoder)
s.Use(func(c martini.Context, w http.ResponseWriter, r *http.Request) {
c.Map(adapterInst)
})
// Setup routes
router := martini.NewRouter()
router.Group(fmt.Sprintf("/%s", APIVersion), func(r martini.Router) {
r.Get(`/services`, getServices)
r.Get(`/services/:id`, getService)
r.Post(`/services`, createServices)
r.Put(`/services/:id`, updateService)
r.Delete(`/services/:id`, deleteService)
r.Get(`/metadata`, getMetadata)
})
// Add the router action
s.Action(router.Handle)
server := martiniServer{svr: s}
return &server
}
示例6: startGUI
func startGUI(addr string, m *model.Model) {
router := martini.NewRouter()
router.Get("/", getRoot)
router.Get("/rest/version", restGetVersion)
router.Get("/rest/model", restGetModel)
router.Get("/rest/connections", restGetConnections)
router.Get("/rest/config", restGetConfig)
router.Get("/rest/need", restGetNeed)
router.Get("/rest/system", restGetSystem)
fs, err := embed.Unpack(Resources)
if err != nil {
panic(err)
}
go func() {
mr := martini.New()
mr.Use(embeddedStatic(fs))
mr.Use(martini.Recovery())
mr.Action(router.Handle)
mr.Map(m)
err := http.ListenAndServe(addr, mr)
if err != nil {
warnln("GUI not possible:", err)
}
}()
}
示例7: main
func main() {
Db = dbSetup()
m := martini.New()
//m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Action(routes().Handle)
m.Run()
}
示例8: newMartini
func newMartini() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
m.Use(middleware.Logger())
m.Use(martini.Recovery())
m.Use(martini.Static("public"))
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}
示例9: newModern
func newModern() *Modern { // customized martini.Classic
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Recovery())
m.Action(r.Handle)
return &Modern{
Martini: m,
Router: r,
}
}
示例10: main
func main() {
// runtime.GOMAXPROCS(runtime.NumCPU())
// fmt.Printf("GOMAXPROCS is %d\n", runtime.GOMAXPROCS(0))
// Server and middleware
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
r := martini.NewRouter()
m.Action(r.Handle)
r.Get("/", func() string {
return "."
})
r.Any("/fetch", func(req *http.Request, res http.ResponseWriter) {
err := req.ParseForm()
if err != nil {
renderMsg(res, 422, "Unable to parse parameters")
return
}
// Grab params and set defaults
urls := req.Form["url"]
if len(urls) == 0 {
urls = req.Form["url[]"]
}
maxtime, _ := strconv.Atoi(req.Form.Get("maxtime"))
if maxtime == 0 {
maxtime = MAXTIME
}
if len(urls) == 0 {
renderMsg(res, 422, "Url parameter required")
return
}
responses := httpFetch(urls, maxtime)
if err != nil {
renderMsg(res, 500, err.Error())
} else {
renderMsg(res, 200, responses)
}
})
// Boot the server
log.Println("** Purls", VERSION, "http server listening on", ADDR)
log.Println("** with thruput:", THRUPUT, "maxtime:", MAXTIME)
if err := http.ListenAndServe(ADDR, m); err != nil {
log.Fatal(err)
}
}
示例11: AppServer
func AppServer() *Server {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(render.Renderer())
m.Use(DB())
m.Action(r.Handle)
return &Server{m, r}
}
示例12: init
func init() {
m = martini.New()
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Frame-Options", "DENY")
w.Header().Set("Strict-Transport-Security", "max-age=60000")
})
m.Use(martini.Static("public"))
m.Use(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
})
r := martini.NewRouter()
r.Put("/candidates", mainHandler)
m.Action(r.Handle)
http.Handle("/", m)
}
示例13: main
func main() {
// START OMIT
m := martini.New()
// Specify what middleware to use
m.Use(martini.Logger())
m.Use(martini.Recovery())
r := martini.NewRouter()
r.Get("/ok", ok)
r.Get("/panic", panicFunc)
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
http.ListenAndServe(":1810", m)
// STOP OMIT
}
示例14: makeService
func makeService(ts tuplespace.RawTupleSpace, debug bool) *martini.Martini {
m := martini.New()
m.Use(martini.Recovery())
if debug {
m.Use(martini.Logger())
}
m.Use(server.SerializationMiddleware())
m.MapTo(ts, (*tuplespace.RawTupleSpace)(nil))
r := martini.NewRouter()
r.Post("/tuplespace/", server.DeserializerMiddleware(SendRequest{}), Send)
r.Get("/tuplespace/", server.DeserializerMiddleware(tuplespace.ReadRequest{}), Read)
r.Delete("/tuplespace/", server.DeserializerMiddleware(tuplespace.ReadRequest{}), Take)
m.Action(r.Handle)
return m
}
示例15: init
func init() {
m = martini.New()
// Setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// Setup routes
r := martini.NewRouter()
r.Get(`/albums`, GetAlbums)
r.Get(`/albums/:id`, GetAlbum)
r.Post(`/albums`, AddAlbum)
r.Put(`/albums/:id`, UpdateAlbum)
r.Delete(`/albums/:id`, DeleteAlbum)
// Inject database
m.MapTo(db, (*DB)(nil))
// Add the router action
m.Action(r.Handle)
}