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:
parent
ac323178df
commit
c2a30de34f
40
examples/middleware/server.go
Normal file
40
examples/middleware/server.go
Normal 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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user