dms

package module
v0.0.0-...-9855862 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

DMS - Dead Mans Switch (kinda)

Usage

go get -u github.com/Schmenn/dms
Example - Gin
package main

import (
	"os"
	"time"

	"github.com/Schmenn/dms"
	"github.com/fatih/color"
	"github.com/gin-gonic/gin"
)

func main() {
	// new gin router
	r := gin.Default()

	// make dead mans switch
	d := dms.DeadManSwitch{
		TimerDuration: time.Second * 5,
		Username:      "coolUsername",
		Password:      "password123",
		OnTrigger: func() {
			color.Cyan(time.Now().Format("[DMS: 15:04:05.000]") + " Deploy the cows")
			os.Exit(0)
		},
	}
    // register endpoint with the dead mans switch
	r.GET("/dms", gin.WrapF(d.Handler()))

	r.Run(":80")
}

Why?

I was bored

Documentation

Index

Constants

View Source
const (
	ErrNoDuration = "[DMS]: no duration given"
	ErrNoUsername = "[DMS]: no username given"
	ErrNoPassword = "[DMS]: no password given"
	ErrNoFunction = "[DMS]: no function given"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeadMansSwitch

type DeadMansSwitch struct {
	// TimerDuration specifies the timespan
	// after which it will run OnTrigger
	// if the Dead Mans Switch was not reset
	TimerDuration time.Duration

	// Username is the username for the Dead
	// Mans Switch which has to be provided
	// via BasicAuth
	Username string

	// Password is the Password for the Dead
	// Mans Switch which has to be provided
	// via BasicAuth
	Password string

	// OnTrigger is the function which gets
	// run once the timer runs out because
	// it was not reset
	OnTrigger func()
}

A DeadManSwitch struct stores values such as Duration and Credentials

func (*DeadMansSwitch) Handler

func (d *DeadMansSwitch) Handler() http.HandlerFunc

Handler returns a http.HandlerFunc which can be used in every web framework/router

func (*DeadMansSwitch) SetOnTrigger

func (d *DeadMansSwitch) SetOnTrigger(f func()) *DeadMansSwitch

SetOnTrigger sets the OnTrigger function of the Dead Mans Switch

func (*DeadMansSwitch) SetPassword

func (d *DeadMansSwitch) SetPassword(p string) *DeadMansSwitch

SetPassword sets the Password of the Dead Mans Switch

func (*DeadMansSwitch) SetTimerDuration

func (d *DeadMansSwitch) SetTimerDuration(t time.Duration) *DeadMansSwitch

SetTimerDuration sets the Timer Duration of the Dead Mans Switch

Jump to

Keyboard shortcuts

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