maintenance

package module
v0.0.0-...-7a3e8f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2018 License: MIT Imports: 6 Imported by: 0

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

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)
}

Documentation

Index

Constants

View Source
const AllowedIPsKey = "maintenance_allowed_ips"
View Source
const MaintenanceKey = "maintenance"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetMaintenance() *maintenanceMode
	GetAllowedIPs() ([]string, error)
	SetMessage([]byte) error
	SetAllowedIPs([]string) error
	Disable() error
	DisableAllowedIPs() error
}

func NewMemcachedClient

func NewMemcachedClient(url string) Client

func NewRedisClient

func NewRedisClient(opt *redis.Options) Client

type Maintenance

type Maintenance interface {
	SetMaintenance(next http.Handler) http.Handler
	AllowByIP(next http.Handler) http.Handler
	ResponseIfMaintenanceMode(next http.Handler) http.Handler
}

func NewMaintenanceMemcachedBackend

func NewMaintenanceMemcachedBackend(url string) Maintenance

func NewMaintenanceRedisBackend

func NewMaintenanceRedisBackend(opt *redis.Options) Maintenance

type MaintenanceMode

type MaintenanceMode interface {
	IsEnabled() bool
	Disable()
}

type MemcachedClient

type MemcachedClient struct {
	URL string
	// contains filtered or unexported fields
}

func (*MemcachedClient) Disable

func (c *MemcachedClient) Disable() error

func (*MemcachedClient) DisableAllowedIPs

func (c *MemcachedClient) DisableAllowedIPs() error

func (*MemcachedClient) GetAllowedIPs

func (c *MemcachedClient) GetAllowedIPs() ([]string, error)

func (*MemcachedClient) GetMaintenance

func (c *MemcachedClient) GetMaintenance() *maintenanceMode

func (*MemcachedClient) SetAllowedIPs

func (c *MemcachedClient) SetAllowedIPs(ips []string) error

func (*MemcachedClient) SetMessage

func (c *MemcachedClient) SetMessage(msg []byte) error

type RedisClient

type RedisClient struct {
	// contains filtered or unexported fields
}

func (*RedisClient) Disable

func (c *RedisClient) Disable() error

func (*RedisClient) DisableAllowedIPs

func (c *RedisClient) DisableAllowedIPs() error

func (*RedisClient) GetAllowedIPs

func (c *RedisClient) GetAllowedIPs() ([]string, error)

func (*RedisClient) GetMaintenance

func (c *RedisClient) GetMaintenance() *maintenanceMode

func (*RedisClient) SetAllowedIPs

func (c *RedisClient) SetAllowedIPs(ips []string) error

func (*RedisClient) SetMessage

func (c *RedisClient) SetMessage(msg []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL