mirror of
https://github.com/labstack/echo.git
synced 2025-01-28 03:29:35 +02:00
a4375c4991
Signed-off-by: Vishal Rana <vr@labstack.com>
59 lines
744 B
Go
59 lines
744 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo"
|
|
mw "github.com/labstack/echo/middleware"
|
|
)
|
|
|
|
// Handler
|
|
func hello(c *echo.Context) error {
|
|
return c.String(http.StatusOK, "Hello, World!\n")
|
|
}
|
|
|
|
func main() {
|
|
// Echo instance
|
|
e := echo.New()
|
|
|
|
// Debug mode
|
|
e.SetDebug(true)
|
|
|
|
//------------
|
|
// Middleware
|
|
//------------
|
|
|
|
// Logger
|
|
e.Use(mw.Logger())
|
|
|
|
// Recover
|
|
e.Use(mw.Recover())
|
|
|
|
// Basic auth
|
|
e.Use(mw.BasicAuth(func(u, p string) bool {
|
|
if u == "joe" && p == "secret" {
|
|
return true
|
|
}
|
|
return false
|
|
}))
|
|
|
|
//-------
|
|
// Slash
|
|
//-------
|
|
|
|
e.Use(mw.StripTrailingSlash())
|
|
|
|
// or
|
|
|
|
// e.Use(mw.RedirectToSlash())
|
|
|
|
// Gzip
|
|
e.Use(mw.Gzip())
|
|
|
|
// Routes
|
|
e.Get("/", hello)
|
|
|
|
// Start server
|
|
e.Run(":1323")
|
|
}
|