servicego

package module
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 8 Imported by: 16

README

servicego

Go Report Card

Background

The servicego package provides a wrapper for the functionality in github.com/kardianos/service

This was written to simplify usage when writing lots of services, eliminating much of the boiler place code to set up a new service.

Defaults

Service name, display name, and description all default to the executable name.

A Brief How-To
go get github.com/mlctrez/servicego

Embed Defaults in a struct for your Service.

type exampleService struct {
    servicego.Defaults
}

Implement Start and Stop as you would in github.com/kardianos/service

func (e *exampleService) Start(s service.Service) error {
    // Start should not block so do non-setup work in goroutines.
    // Return non nil error if the service cannot be started.
}

func (e *exampleService) Stop(s service.Service) error {
    // Cancel goroutines if you require a graceful shutdown.
    // Stop should not block and should return with a few seconds.
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustExecutable

func MustExecutable() string

func Run

func Run(s Service)

Run is intended to be only called from a main method

func ServiceDirectory

func ServiceDirectory() string

func ServiceName

func ServiceName() string

Types

type ConfigProvider

type ConfigProvider interface {
	// Config provides the configuration for service.New
	Config() *service.Config
}

ConfigProvider provides the service.Config for a Service

type DefaultConfig

type DefaultConfig struct{}

func (*DefaultConfig) Config

func (d *DefaultConfig) Config() *service.Config

type DefaultLogger

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

DefaultLogger is provides a default implementation of LoggerContainer for a Service

func (*DefaultLogger) Errorf added in v1.4.6

func (d *DefaultLogger) Errorf(format string, args ...interface{})

func (*DefaultLogger) Infof added in v1.4.6

func (d *DefaultLogger) Infof(format string, args ...interface{})

func (*DefaultLogger) Log

func (d *DefaultLogger) Log() service.Logger

func (*DefaultLogger) Logger

func (d *DefaultLogger) Logger(logger service.Logger)

type Defaults

type Defaults struct {
	DefaultConfig
	DefaultLogger
}

type LoggerContainer

type LoggerContainer interface {
	// Logger is called with the output
	Logger(logger service.Logger)
	// Log provides access to the DefaultLogger logger
	//
	// This should not be used until after Run is called
	Log() service.Logger
}

LoggerContainer makes the service.Logger available to the Service

type Service

type Service interface {
	service.Interface
	ConfigProvider
	LoggerContainer
}

Service extends the service.Interface for setup of service.Config and service.Logger

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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