Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sachaos/maintenance
Golang net/http middleware, provide maintenance feature to your app.
https://github.com/sachaos/maintenance
go golang maintenance middleware
Last synced: about 1 month ago
JSON representation
Golang net/http middleware, provide maintenance feature to your app.
- Host: GitHub
- URL: https://github.com/sachaos/maintenance
- Owner: sachaos
- License: mit
- Created: 2018-02-04T07:15:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-20T17:19:21.000Z (almost 7 years ago)
- Last Synced: 2024-11-26T18:08:55.109Z (about 1 month ago)
- Topics: go, golang, maintenance, middleware
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Maintenance
===`maintenance` is little Golang `net/http` middleware to add maintenance feature to your app.
Features
---* IP address white list.
Usage
---## Install
```
go get github.com/sachaos/maintenance
```## Sample
```go
package mainimport (
"fmt"
"net/http"
"os""github.com/go-chi/chi"
"github.com/sachaos/maintenance"
)func main() {
// Create maintenance instance with backend memcached url
memcachedUrl := os.Getenv("MEMCACHED_SERVER")
m := maintenance.NewMaintenance(memcachedUrl)r := chi.NewRouter()
r.Use(m.SetMaintenance) // Set MaintenanceMode in request context
r.Use(m.AllowByIP) // Enable IP white list
r.Use(m.ResponseIfMaintenanceMode) // If maintenance mode enabled, response specifield message with 503.r.Get("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Request Succeeded")
})http.ListenAndServe(":3000", r)
}
```