本文整理汇总了Golang中github.com/labstack/echo/middleware.Recover函数的典型用法代码示例。如果您正苦于以下问题:Golang Recover函数的具体用法?Golang Recover怎么用?Golang Recover使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Recover函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:xyproto,项目名称:echo,代码行数:48,代码来源:server.go
示例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))
}
开发者ID:itang,项目名称:gomonkey,代码行数:25,代码来源:server.go
示例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
}
开发者ID:Rompei,项目名称:zepher-bansaku,代码行数:30,代码来源:routes.go
示例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")
}
开发者ID:aslijiasheng,项目名称:jasongo,代码行数:34,代码来源:server.go
示例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"))
}
开发者ID:plumbum,项目名称:go-samples,代码行数:31,代码来源:main.go
示例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")
}
开发者ID:MeoBlodnasir,项目名称:community,代码行数:34,代码来源:main.go
示例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"))
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:26,代码来源:server.go
示例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
}
开发者ID:nlamirault,项目名称:abraracourcix,代码行数:28,代码来源:handlers.go
示例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)
}
开发者ID:fgrehm,项目名称:pucrs-iot-experiment,代码行数:35,代码来源:main.go
示例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)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:32,代码来源:main.go
示例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)
}
开发者ID:Gentux,项目名称:nanocloud-old,代码行数:30,代码来源:main.go
示例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
}
开发者ID:kerkerj,项目名称:gtg15-demo,代码行数:35,代码来源:api.go
示例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)
}
}
开发者ID:AlexThurston,项目名称:skipp3r,代码行数:30,代码来源:main.go
示例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")
}
开发者ID:prabirshrestha,项目名称:echo,代码行数:34,代码来源:server.go
示例15: registerMiddlewares
func (as ApiService) registerMiddlewares() {
// Middlewares
as.echo.HTTPErrorHandler = CustomHTTPErrorHandler
as.echo.Use(middleware.Logger())
as.echo.Use(middleware.Recover())
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:7,代码来源:api.go
示例16: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
fetchFeed()
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.StripTrailingSlash())
e.Use(mw.Gzip())
e.Use(cors.Default().Handler)
bundle, _ := ioutil.ReadFile("./build/bundle.js")
// stats
s := stats.New()
e.Use(s.Handler)
e.Get("/stats", func(c *echo.Context) error {
return c.JSON(http.StatusOK, s.Data())
})
// static files
e.Static("/public/css", "public/css")
e.Static("/universal.js", "./build/bundle.js")
e.Favicon("public/favicon.ico")
e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), rss))
e.Get("/about", selfjs.New(runtime.NumCPU(), string(bundle), loremJSON()))
e.Get("/api/data", apiFrontPage)
e.Get("/api/anotherpage", apiAnotherPage)
go tick()
fmt.Println("serving at port 3000")
e.Run(":3000")
}
开发者ID:jelinden,项目名称:go-isomorphic-react-v8,代码行数:33,代码来源:main.go
示例17: main
func main() {
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Static("/", "public")
e.WebSocket("/ws", func(c *echo.Context) (err error) {
ws := c.Socket()
msg := ""
for {
if err = websocket.Message.Send(ws, "Hello, Client!"); err != nil {
return
}
if err = websocket.Message.Receive(ws, &msg); err != nil {
return
}
println(msg)
}
return
})
e.Run(":1323")
}
开发者ID:ZhiqinYang,项目名称:echo,代码行数:25,代码来源:server.go
示例18: main
func main() {
e := echo.New()
e.Debug()
//Midleware
e.Use(mw.Logger())
e.Use(mw.Recover())
e.SetHTTPErrorHandler(func(err error, c *echo.Context) {
log.Println(err)
e.DefaultHTTPErrorHandler(err, c)
})
//Handlers
e.Post("/Plugin.Activate", PluginActivate)
e.Post("/NetworkDriver.CreateNetwork", NetworkDriverCreateNetwork)
e.Post("/NetworkDriver.DeleteNetwork", NetworkDriverDeleteNetwork)
e.Post("/NetworkDriver.CreateEndpoint", NetworkDriverCreateEndpoint)
e.Post("/NetworkDriver.EndpointOperInfo", NetworkDriverEndpointOperInfo)
e.Post("/NetworkDriver.DeleteEndpoint", NetworkDriverDeleteEndpoint)
e.Post("/NetworkDriver.Join", NetworkDriverJoin)
e.Post("/NetworkDriver.Leave", NetworkDriverLeave)
e.Run(":1313")
}
开发者ID:anarcher,项目名称:docker-vlan-driver,代码行数:26,代码来源:main.go
示例19: main
func main() {
echo_serve := echo.New()
mws := []echo.Middleware{mw.Logger(), mw.Recover(), mw.Gzip()}
//注册日志、故障恢复、响应Gzip压缩中间件
echo_serve.Use(mws...)
// echo_serve.Static("/","templates")
// echo_serve.Static("/js","sources/scripts")
// echo_serve.Static("/css","sources/css")
//
// echo_serve.Index("templates/index.html")
tmpl, err := template.ParseGlob("templates/*.html")
if err != nil {
fmt.Print(err.Error())
}
t := &Template{
templates: template.Must(tmpl, err),
}
echo_serve.SetRenderer(t)
echo_serve.Get("/hello", Hello)
echo_serve.Run(":9060")
}
开发者ID:salJoker,项目名称:59593364,代码行数:26,代码来源:main.go
示例20: main
func main() {
// inti config and component
componentInit()
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// e.Use(handler.CrossDomain)
// Routes
e.Get("/hello", handler.Hello)
e.Get("/api/v1/seckill", handler.Tickets)
e.Get("/api/v1/reset", handler.Reset)
// go cache.StartUpdateEventStatus()
// go kafka.StartKafkaProducer()
// Start server
port := viper.GetString("port")
log.Println("server port: ", port)
graceful.ListenAndServe(e.Server(port), 1*time.Second)
}
开发者ID:Dataman-Cloud,项目名称:seckilling,代码行数:26,代码来源:main.go
注:本文中的github.com/labstack/echo/middleware.Recover函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论