Middleware for echo framework to make all requests respond according to a handler function based on the presence/absence of a file specified. It is built with go version go1.13.1 darwin/amd64
go get -u "github.com/rakutentech/go-echo-maintenance"
package main
import (
"net/http"
maintenance "github.com/rakutentech/go-echo-maintenance"
"github.com/labstack/echo"
)
func customHandlerFunc(c echo.Context) error {
return c.HTML(http.StatusNotFound, `<h1 style="color:red;">Request is intercepted by maintenance middleware!</h1>`)
}
func main() {
e := echo.New()
middleware := maintenance.NewMaintMiddleware("/path/to/maint/file", customHandlerFunc)
e.Use(middleware.CheckMaintenance)
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
touch /path/to/maint/file
The middleware will intercept requests to api domain and respond according to the custom handler specified by user.
rm /path/to/maint/file
The middleware will no longer intercept requests to api domain.