svc

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// StartError is the type of error returned by the Start method of Lifecycle
	StartError = ErrorType(iota)

	// ExitError is the type of error returned by the Run method of Lifecycle
	ExitError

	// StopError is the type of error returned by the Close method of Lifecycle
	StopError

	// ServiceError is the type of system service error
	ServiceError
)

Variables

Functions

func DefaultErrorCallback

func DefaultErrorCallback(err *Error)

func DefaultExitCodeGetter

func DefaultExitCodeGetter(err *Error) int

func DefaultSignalCallback

func DefaultSignalCallback(sig os.Signal) bool

func LogErrorCallback

func LogErrorCallback(log *log.Logger) func(err *Error)

func SystemdNotify

func SystemdNotify(state string) error

SystemdNotify function notify service manager about start-up completion and other service status changes

Types

type Error

type Error struct {
	Type ErrorType
	Err  error
}

func (Error) Error

func (e Error) Error() string

type ErrorType

type ErrorType int

func (ErrorType) Type

func (t ErrorType) Type() string

Type method return the name of error type, If the error type is undefined, return UNKNOWN_ERROR

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Service.

func ErrorCallback

func ErrorCallback(callback func(err *Error)) Option

ErrorCallback Option specifies the callback function for the Service when an error occurs

func ExitCodeGetter

func ExitCodeGetter(exitCodeGetter func(err *Error) int) Option

ExitCodeGetter Option specifies the callback function for the Service to obtain the program exit code

func OnClosed

func OnClosed(callback func(s Service, l lifecycle.Lifecycle)) Option

func OnStarted

func OnStarted(callback func(s Service, l lifecycle.Lifecycle)) Option

func SignalNotify

func SignalNotify(callback func(sig os.Signal) (exit bool), sig ...os.Signal) Option

SignalNotify Option specifies the callback function when capturing the signal to be notified, if callback return true, If the callback function returns true, the program will start to exit

func WithNotify

func WithNotify(notify bool) Option

type Service

type Service interface {
	// Run method is the main function of program running. The Run method
	// needs to include the implementation of notifying the system service
	// daemon(e.g. linux systemd or Windows service manager) when the
	// program starts, exits, or has errors
	Run() (exitCode int)
}

Service interface specifies the behavior of the system service

func New

func New(name string, app lifecycle.Lifecycle, options ...Option) Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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