Version: v0.4.9 Latest Latest

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

Go to latest
Published: Dec 23, 2020 License: MIT Imports: 11 Imported by: 3



Diamond package provides runlevels to an application

API is considered unstable until further notice



This section is empty.


View Source
var CHMODDIR os.FileMode = 0750

CHMODDIR by default is user read/write/searchable, group read/writable

View Source
var CHMODFILE os.FileMode = 0770

CHMODFILE (control socket) by default is user/group read/write/exectuable


This section is empty.


type Client

type Client struct {
	ServerName string // gets filled in with rpc, optional.
	Name       string // optional, can be sent to identify the admin
	// contains filtered or unexported fields

Client connects to a diamond.Server via unix socket

func NewClient

func NewClient(socketpath string) (*Client, error)

NewClient returns an initialized Client, returning an error only if the socket can not be resolved It is possible that the socket does not exist yet

func (*Client) GetSocket

func (c *Client) GetSocket() string

GetSocket returns the filename of socket used for connections

func (*Client) Send

func (c *Client) Send(cmd string, args ...string) (reply string, err error)

Send command and optional arguments and return the reply and any errors Commands available to the client are exported methods of Packet type:

  • returning error
  • first argument of string ("args")
  • second argument of pointer to string (used as "reply")

type Options

type Options struct {
	// More verbose output
	Verbose bool

	// Able to be KICKed via control socket (same as command 'runlevel 0')
	Kickable bool

	// Force runlevel mode, regardless of errors
	Force bool

Options modify how the diamond system functions

type RunlevelFunc

type RunlevelFunc func() error

RunlevelFunc is any function with no arguments that returns an error It can be a method, such as `func (f foo) runlevel9000() error {}`

type System

type System struct {

	// Config can be configured
	Config *Options

	// Log can be redirected
	Log    *log.Logger
	Server *http.Server
	// contains filtered or unexported fields

System listens on control socket, controlling listeners and runlevels

func New

func New(socket string) (*System, error)

New diamond system, listening at specified socket.

func NewServer

func NewServer(handler http.Handler, socket string) (*System, error)

NewServer returns a new server, and an error if the socket path is not valid

func (*System) AddListener

func (s *System) AddListener(ltype, laddr string) (n int, err error)

AddListener to the list of listeners, returning the

func (*System) GetListener

func (s *System) GetListener(n int) net.Listener

Get a listener by index

func (*System) GetRunlevel

func (s *System) GetRunlevel() int

func (*System) NListeners

func (s *System) NListeners() int

func (*System) Runlevel

func (s *System) Runlevel(level int) (err error)

Runlevel switches gears, into the specified level. func main() typically should os.Exit(0) some time after s.Wait()

func (*System) SetHandler

func (s *System) SetHandler(h http.Handler) error

SetHandler for all future connections via http socket or tcp listeners This is only useful for web applications and can be safely ignored

func (*System) SetRunlevel

func (s *System) SetRunlevel(level int, fn RunlevelFunc)

func (*System) Wait

func (s *System) Wait() int

Wait until runlevel 0 is finished (after running custom RunlevelFunc 0 and socket is removed)

Jump to

Keyboard shortcuts

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