本文整理汇总了Golang中github.com/go-martini/martini.Recovery函数的典型用法代码示例。如果您正苦于以下问题:Golang Recovery函数的具体用法?Golang Recovery怎么用?Golang Recovery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Recovery函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mount
func mount(war string) {
log.Println("mount")
m := martini.Classic()
m.Handlers(martini.Recovery())
m.Use(martini.Static(war, martini.StaticOptions{SkipLogging: true}))
m.Use(render.Renderer(render.Options{
Extensions: []string{".html", ".shtml"},
}))
broker = NewBroker()
m.Map(broker)
m.Get("/", indexHandler)
m.Get("/events/", sseHandler)
http.Handle("/", m)
go func() {
for i := 0; ; i++ {
// Create a little message to send to clients,
// including the current time.
broker.messages <- fmt.Sprintf(" %d - 哈哈,Oh, Yeah!!! - the time is %v", i, time.Now())
// Print a nice log message and sleep for 5s.
log.Printf("Sent message %d ", i)
time.Sleep(5 * 1e9)
}
}()
}
示例2: Start
func Start() {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
// Gitchain API
r.Post("/rpc", jsonRpcService().ServeHTTP)
r.Get("/info", info)
// Git Server
r.Post("^(?P<path>.*)/git-upload-pack$", func(params martini.Params, req *http.Request) string {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return params["path"]
})
r.Post("^(?P<path>.*)/git-receive-pack$", func(params martini.Params, req *http.Request) string {
fmt.Println(req)
return params["path"]
})
r.Get("^(?P<path>.*)/info/refs$", func(params martini.Params, req *http.Request) (int, string) {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return 404, params["path"]
})
log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", env.Port), m))
}
示例3: main
func main() {
username, password := waitForPostgres(serviceName)
db, err := postgres.Open(serviceName, fmt.Sprintf("dbname=postgres user=%s password=%s", username, password))
if err != nil {
log.Fatal(err)
}
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(render.Renderer())
m.Action(r.Handle)
m.Map(db)
r.Post("/databases", createDatabase)
r.Get("/ping", ping)
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
if err := discoverd.Register(serviceName+"-api", addr); err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(addr, m))
}
示例4: init
func init() {
m = martini.New()
//setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(martini.Static("public"))
}
示例5: main
/*
Application entry point
*/
func main() {
m := martini.New()
//Set middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"OPTIONS", "HEAD", "POST", "GET", "PUT"},
AllowHeaders: []string{"Authorization", "Content-Type"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
//Create the router
r := martini.NewRouter()
//Options matches all and sends okay
r.Options(".*", func() (int, string) {
return 200, "ok"
})
api.SetupTodoRoutes(r)
api.SetupCommentRoutes(r)
mscore.StartServer(m, r)
fmt.Println("Started NSQ Test service")
}
示例6: mount
func mount(war string) {
m := martini.Classic()
m.Handlers(martini.Recovery())
m.Use(gzip.All())
m.Use(martini.Static(war, martini.StaticOptions{SkipLogging: true}))
// m.Use(render.Renderer(render.Options{
// Extensions: []string{".html", ".shtml"},
// }))
// m.Use(render.Renderer())
// m.Use(midTextDefault)
//map web
m.Use(func(w http.ResponseWriter, c martini.Context) {
web := &Web{w: w}
c.Map(web)
})
m.Group("/test", func(api martini.Router) {
api.Get("", mainHandler)
api.Get("/1", test1Handler)
api.Get("/2", test2Handler)
})
http.Handle("/", m)
}
示例7: launchFrontend
func launchFrontend() {
m := martini.New()
m.Use(martini.Static("static"))
m.Use(martini.Recovery())
m.Use(martini.Logger())
r := martini.NewRouter()
r.Get("/", indexHandler)
r.Get("/following", followHandler)
r.Get("/stat", statHandler)
r.Get("/channel/:streamer", channelHandler)
r.Get("/add/:streamer", addHandler)
r.Get("/del/:streamer", delHandler)
r.Get("/api/stat/:streamer", apiStat)
r.Get("/api/channel/:streamer", apiStat)
r.Get("/api/following", apiFollowing)
db := getDB()
redis := getRedis()
m.Map(db)
m.Map(redis)
m.Action(r.Handle)
log.Print("Started Web Server")
m.Run()
}
示例8: init
func init() {
m = martini.New()
//set up middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// set up 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
// maps db package variable to the DB interface defined in data.go
// The syntax for the second parameter may seem weird,
// it is just converting nil to the pointer-to-DB-interface type,
// because all the injector needs is the type to map the first parameter to.
m.MapTo(db, (*DB)(nil))
// add route action
// adds the router’s configuration to the list of handlers that Martini will call.
m.Action(r.Handle)
}
示例9: main
func main() {
log.Println("server start11")
fmt.Printf("access_token:%s", ACCESS_TOKEN)
m := martini.Classic()
m.Handlers(martini.Recovery())
m.Use(render.Renderer(render.Options{
Extensions: []string{".html", ".shtml"},
}))
m.Get("/", checkSignatureHandler)
m.Post("/", transceiverMsgHandler)
m.Get("/createMenu", createMenuHandler)
m.Get("/hi", func() string {
return "Hello world!"
})
http.Handle("/", m)
if martini.Env == martini.Dev {
HOST = ":8080"
} else {
HOST = ":80"
}
log.Printf("start web server on %s", HOST)
http.ListenAndServe(HOST, nil)
}
示例10: init
func init() {
m = martini.New()
// I could probably just use martini.Classic() instead of configure these manually
// Static files
m.Use(martini.Static(`public`))
// 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`, server.GetAlbums)
r.Get(`/albums/:id`, server.GetAlbum)
r.Post(`/albums`, server.AddAlbum)
r.Put(`/albums/:id`, server.UpdateAlbum)
r.Delete(`/albums/:id`, server.DeleteAlbum)
// Inject database
m.MapTo(server.DBInstance, (*server.DB)(nil))
// Add the router action
m.Action(r.Handle)
}
示例11: withoutLogging
func withoutLogging() *myClassic {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &myClassic{m, r}
}
示例12: NewWebService
// NewWebService creates a new web service ready to run.
func NewWebService() *martini.Martini {
m := martini.New()
m.Handlers(loggerMiddleware(), martini.Recovery(), gzip.All())
r := newRouter()
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return m
}
示例13: main
func main() {
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(martini.Static("public"))
r := martini.NewRouter()
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
// Instantiate OAuthService with the OAuth App Client Id & Secret from the Environment Variables
o, err := coinbase.OAuthService(os.Getenv("COINBASE_CLIENT_ID"), os.Getenv("COINBASE_CLIENT_SECRET"), "https://localhost:8443/tokens")
if err != nil {
panic(err)
return
}
// At https://localhost:8443/ we will display an "authorize" link
r.Get("/", func() string {
authorizeUrl := o.CreateAuthorizeUrl([]string{
"user",
"balance",
})
link := "<a href='" + authorizeUrl + "'>authorize</a>"
return link
})
// AuthorizeUrl redirects to https://localhost:8443/tokens with 'code' in its
// query params. If you dont have SSL enabled, replace 'https' with 'http'
// and reload the page. If successful, the user's balance will show
r.Get("/tokens", func(res http.ResponseWriter, req *http.Request) string {
// Get the tokens given the 'code' query param
tokens, err := o.NewTokensFromRequest(req) // Will use 'code' query param from req
if err != nil {
return err.Error()
}
// instantiate the OAuthClient
c := coinbase.OAuthClient(tokens)
amount, err := c.GetBalance()
if err != nil {
return err.Error()
}
return strconv.FormatFloat(amount, 'f', 6, 64)
})
// HTTP
go func() {
if err := http.ListenAndServe(":8080", m); err != nil {
log.Fatal(err)
}
}()
// HTTPS
// To generate a development cert and key, run the following from your *nix terminal:
// go run $(go env GOROOT)/src/pkg/crypto/tls/generate_cert.go --host="localhost"
if err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", m); err != nil {
log.Fatal(err)
}
}
示例14: NewMartini
func NewMartini() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Recovery())
m.Use(render.Renderer())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{Martini: m, Router: r}
}
示例15: nolog
func nolog() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Recovery())
m.Use(martini.Static("public"))
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}