1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-16 02:33:26 +02:00

Added http basic auth example

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-05-11 20:52:43 -07:00
parent ac323178df
commit c2a30de34f

View File

@ -0,0 +1,40 @@
package main
import (
"net/http"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
// Handler
func hello(c *echo.Context) *echo.HTTPError {
return c.String(http.StatusOK, "Hello, World!\n")
}
func main() {
// Echo instance
e := echo.New()
//------------
// Middleware
//------------
// Logger
e.Use(mw.Logger)
// Basic auth
e.Use(mw.BasicAuth(func(u, p string) bool {
println(u, p)
if u == "joe" && p == "secret" {
return true
}
return false
}))
// Routes
e.Get("/", hello)
// Start server
e.Run(":1323")
}