Skip to content

Golang net/http middleware, provide maintenance feature to your app.

License

Notifications You must be signed in to change notification settings

sachaos/maintenance

Repository files navigation

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

package main

import (
	"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)
}

About

Golang net/http middleware, provide maintenance feature to your app.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published