killswitch

package
v0.0.2-rc-ci Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHash = xerror.BadInputError{Err: fmt.Errorf("invalid hash")}

ErrInvalidHash indicates an invalid hash was provided.

Functions

func Middleware

func Middleware(service Service) func(next http.Handler) http.Handler

Middleware returns a new killswitch middleware. It checks wether the state is on. If not it writes a 503 response.

func Router

func Router(service Service) func(chi.Router)

Router returns a new killswitch router.

Types

type FileStore

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

func NewFileStore

func NewFileStore(filePath string, watcherRate time.Duration) *FileStore

func (*FileStore) GetState

func (f *FileStore) GetState(ctx context.Context) (bool, error)

func (*FileStore) SetState

func (f *FileStore) SetState(ctx context.Context, on bool) error

func (*FileStore) Stop

func (f *FileStore) Stop()

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) GetState

func (m *MemoryStore) GetState(ctx context.Context) (bool, error)

func (*MemoryStore) SetState

func (m *MemoryStore) SetState(ctx context.Context, on bool) error

type Service

type Service interface {
	// TurnOff tries to set the the state to off.
	// Returns an error if the hash is invalid.
	TurnOff(ctx context.Context, hash string) error
	// TurnOn tries to set the the state to on.
	// Returns an error if the hash is invalid.
	TurnOn(ctx context.Context, hash string) error
	// On returns wether the current state is set to on.
	On(ctx context.Context) (bool, error)
}

Service defines an interface for interacting with a killswitch service.

-go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/killswitch Service --output=../../internal/mock/killswitch_service.go --package=mock --mock-name=KillswitchService

func NewService

func NewService(storer Storer, hashes []string) Service

NewService returns a new killswitch service. It takes a list of hashes, that can be used to turn the state on or off.

type Storer

type Storer interface {
	// SetState sets the state of the killswitch.
	SetState(ctx context.Context, on bool) error
	// GetState retrieves the state of the killswitch.
	GetState(ctx context.Context) (bool, error)
}

Storer provides methods to store or retrive the killswitch state. The state can either be on or off.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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