本文整理匯總了Golang中github.com/labstack/echo/middleware.Recover函數的典型用法代碼示例。如果您正苦於以下問題:Golang Recover函數的具體用法?Golang Recover怎麽用?Golang Recover使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Recover函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Host map
hosts := make(Hosts)
//-----
// API
//-----
api := echo.New()
api.Use(mw.Logger())
api.Use(mw.Recover())
hosts["api.localhost:1323"] = api
api.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "API")
})
//------
// Blog
//------
blog := echo.New()
api.Use(mw.Logger())
api.Use(mw.Recover())
hosts["blog.localhost:1323"] = blog
blog.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Blog")
})
//---------
// Website
//---------
site := echo.New()
site.Use(mw.Logger())
site.Use(mw.Recover())
hosts["localhost:1323"] = site
site.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Welcome!")
})
http.ListenAndServe(":1323", hosts)
}
示例2: main
func main() {
//runtime.GOMAXPROCS(runtime.NumCPU())
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
e.Get("/", welcome)
e.Get("/ping", ping)
//// Start server
//e.Run(":1323")
// Get the http.Server
s := e.Server(":8000")
// HTTP2 is currently enabled by default in echo.New(). To override TLS handshake errors
// you will need to override the TLSConfig for the server so it does not attempt to validate
// the connection using TLS as required by HTTP2
s.TLSConfig = nil
// Serve it like a boss
log.Fatal(gracehttp.Serve(s))
}
示例3: NewRoutes
// NewRoutes return routes
func NewRoutes() *echo.Echo {
bansaku := echo.New()
bansaku.Static("/js", "static/js")
bansaku.Static("/css", "static/css/bansaku")
bansaku.Static("/sound", "static/sound")
bansaku.Static("/font", "static/font")
bansaku.Use(mw.Logger())
bansaku.Use(mw.Recover())
t := p.PrepareTemplates(p.Options{
Directory: "templates/",
Extensions: []string{".tpl"},
})
bansaku.SetRenderer(t)
// Debug
bansaku.SetDebug(true)
server := controllers.NewBansakuServer()
go server.Start()
bansaku.Get("/", controllers.BansakuIndex)
bansaku.WebSocket("/ws", server.BansakuSocketHandler())
// API
api := bansaku.Group("/api")
api.Static("/css", "static/css/api")
api.Get("/", controllers.APIReferenceHandler)
api.Get("/count", controllers.APIBansakuGetHandler)
return bansaku
}
示例4: main
func main() {
loggerService.FileHandle = "server.go"
loggerService.ErrMsg = string("init server.go")
loggerService.Count = len("init server.go")
loggerService.Level = "DEBUG"
gLoggerService.LogInit(loggerService)
go putEnginePoll()
// Echo instance
e := echo.New()
// Debug mode
e.Debug()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
// Routes
e.Get("/expressListUsers", expressListUsers)
e.Post("/expressEmailMessage", expressEmailMessage)
e.Post("/expressQueryUsers", expressQueryUsers)
e.Post("/expressTake", expressTake)
e.Get("/expressTakeUser", expressTakeUser)
loggerService.FileHandle = "server.go"
loggerService.ErrMsg = string("1323 succ server.go")
loggerService.Count = len("1323 succ server.go")
loggerService.Level = "DEBUG"
gLoggerService.LogInit(loggerService)
// Start server
e.Run(":1323")
}
示例5: main
func main() {
demoData := Data{
Id: 5,
Name: "User name",
Tags: []string{"people", "customer", "developer"},
}
e := echo.New()
e.SetDebug(true)
e.Use(middleware.Logger())
e.Use(middleware.Recover())
s := stats.New()
e.Use(standard.WrapMiddleware(s.Handler))
e.GET("/xml", func(c echo.Context) error {
return c.XML(200, demoData)
})
e.GET("/json", func(c echo.Context) error {
return c.JSON(200, demoData)
})
e.GET("/error", func(c echo.Context) error {
return echo.NewHTTPError(500, "Error here")
})
e.Run(standard.New(":8888"))
}
示例6: main
func main() {
conf.Server = env("SERVER", "127.0.0.1")
conf.Password = env("PASSWORD", "ItsPass1942+")
conf.User = env("USER", "Administrator")
conf.SSHPort = env("SSH_PORT", "22")
conf.instDir = os.Getenv("INSTALLATION_DIR")
if len(conf.instDir) == 0 {
conf.instDir = "/var/lib/nanocloud"
}
conf.artURL = os.Getenv("ARTIFACT_URL")
if len(conf.artURL) == 0 {
conf.artURL = "http://releases.nanocloud.org:8080/releases/latest/"
}
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
h := handler{
iaasCon: iaas.New(conf.Server, conf.Password, conf.User, conf.SSHPort, conf.instDir, conf.artURL),
}
e.Get("/api/iaas", h.ListRunningVM)
e.Post("/api/iaas/:id/stop", h.StopVM)
e.Post("/api/iaas/:id/start", h.StartVM)
e.Post("/api/iaas/:id/download", h.DownloadVM)
e.Run(":8080")
}
示例7: main
func main() {
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Login route
e.POST("/login", login)
// Unauthenticated route
e.GET("/", accessible)
// Restricted group
r := e.Group("/restricted")
// Configure middleware with the custom claims type
config := middleware.JWTConfig{
Claims: &jwtCustomClaims{},
SigningKey: []byte("secret"),
}
r.Use(middleware.JWTWithConfig(config))
r.GET("", restricted)
e.Logger.Fatal(e.Start(":1323"))
}
示例8: GetWebService
// GetWebService return a new gin.Engine
func GetWebService(store storage.Storage, auth *Authentication) *echo.Echo {
log.Printf("[DEBUG] [abraracourcix] Creating web service using %v",
store)
ws := v1.NewWebService(store)
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.Get("/", ws.Help())
e.Get("/:url", ws.Redirect())
e.Get("/api/version", ws.DisplayAPIVersion())
v1 := e.Group("/api/v1")
if auth != nil {
log.Printf("[INFO] [abraracourcix] Setup secure mode : %v", auth)
v1.Use(middleware.BasicAuth(func(user string, pwd string) bool {
if user == auth.Username && pwd == auth.Password {
return true
}
return false
}))
}
v1.Get("/urls/:url", ws.URLShow())
v1.Post("/urls", ws.URLCreate())
v1.Get("/stats/:url", ws.URLStats())
return e
}
示例9: main
func main() {
port := "8080"
e := echo.New()
e.SetDebug(true)
e.Use(mw.Logger())
e.Use(mw.Recover())
e.StripTrailingSlash()
assetHandler := http.FileServer(assetFS())
e.Get("/clicks", buttonsStateHandler)
e.Post("/click/:button", buttonClicker)
e.WebSocket("/ws", socketHandler)
e.Get("/*", func(c *echo.Context) error {
assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
return nil
})
// Start the "message hub"
go hub.Run()
// Detect clicks on buttons
btns = newButtons()
defer btns.Close()
btns.Run()
// Control the leds based on clicks
newLeds(btns, hub)
// Start server
log.Println("Starting server on port " + port)
graceful.ListenAndServe(e.Server(":"+port), 2*time.Second)
}
示例10: main
func main() {
// 支持根據參數打印版本信息
global.PrintVersion(os.Stdout)
savePid()
logger.Init(ROOT+"/log", ConfigFile.MustValue("global", "log_level", "DEBUG"))
go ServeBackGround()
e := echo.New()
serveStatic(e)
e.Use(thirdmw.EchoLogger())
e.Use(mw.Recover())
e.Use(pwm.Installed(filterPrefixs))
e.Use(pwm.HTTPError())
e.Use(pwm.AutoLogin())
frontG := e.Group("", thirdmw.EchoCache())
controller.RegisterRoutes(frontG)
frontG.GET("/admin", echo.HandlerFunc(admin.AdminIndex), pwm.NeedLogin(), pwm.AdminAuth())
adminG := e.Group("/admin", pwm.NeedLogin(), pwm.AdminAuth())
admin.RegisterRoutes(adminG)
std := standard.New(getAddr())
std.SetHandler(e)
gracefulRun(std)
}
示例11: main
func main() {
module = nano.RegisterModule("router")
setupDb()
conf.UploadDir = env("UPLOAD_DIR", "uploads/")
handler := httpHandler{
URLPrefix: "/api",
Module: module,
}
go module.Listen()
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
frontDir := env("FRONT_DIR", "front/")
e.Static("/", frontDir)
e.Get("/api/me", getMeHandler)
e.Get("/api/version", getVersionHandler)
e.Any("/api/*", handler.ServeHTTP)
e.Any("/oauth/*", oauthHandler)
e.Post("/upload", uploadHandler)
e.Get("/upload", checkUploadHandler)
addr := ":" + env("PORT", "8080")
module.Log.Info("Server running at ", addr)
e.Run(addr)
}
示例12: Handler
func (api *ApiEcho) Handler() http.Handler {
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Serve static files
e.Static("/", "./public")
// stats https://github.com/thoas/stats
s := stats.New()
e.Use(s.Handler)
e.Get("/stats", func(c *echo.Context) error {
return c.JSON(http.StatusOK, s.Data())
})
// ping
e.Get("/ping", pingHandler())
// Set RGB
e.Get("/rgb/:rgb", rgbHandler(api))
// SetStabilization
e.Get("/stable/:bool", stableHandler(api))
// SetBackLED
e.Get("/backled/:level", backLedHandler(api))
// SetHeading
e.Get("/heading/:heading", headingHandler(api))
// Roll
e.Get("/roll/:speed/head/:heading", rollHandler(api))
// SetRotationRate
e.Get("/rotate_rate/:level", rotationRateHandler(api))
return e
}
示例13: main
func main() {
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
aws_config := aws.NewConfig()
skipp3r = Skipp3r{
Bucket: bucket,
Prefix: prefix,
Version: version,
Svc: s3.New(aws_config),
}
switch cmd {
case get.FullCommand():
res := skipp3r.get(getPath)
fmt.Println(res)
case set.FullCommand():
err := skipp3r.set(srcPath, destPath, doDelete)
fmt.Println(err)
case daemon.FullCommand():
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Get("/", getHandler)
e.Get("/:path", getHandler)
e.Run(":" + *port)
}
}
示例14: main
func main() {
// Echo instance
e := echo.New()
// Debug mode
e.Debug()
//------------
// Middleware
//------------
// Logger
e.Use(mw.Logger())
// Recover
e.Use(mw.Recover())
// Basic auth
e.Use(mw.BasicAuth(func(usr, pwd string) bool {
if usr == "joe" && pwd == "secret" {
return true
}
return false
}))
// Gzip
e.Use(mw.Gzip())
// Routes
e.Get("/", hello)
// Start server
e.Run(":1323")
}
示例15: registerMiddlewares
func (as ApiService) registerMiddlewares() {
// Middlewares
as.echo.HTTPErrorHandler = CustomHTTPErrorHandler
as.echo.Use(middleware.Logger())
as.echo.Use(middleware.Recover())
}