serviceutil

package
v0.0.0-...-84d73a6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package serviceutil contains useful experiments and utilities that have not yet reached the level of robustness required to be part of the service package.

Index

Constants

View Source
const DefaultShutdownTimeout = 5 * time.Second

Variables

This section is empty.

Functions

func IsRestartLimitExceeded

func IsRestartLimitExceeded(err error) bool

Types

type HTTP

type HTTP struct {
	Name   service.Name
	Server *http.Server

	// When the service is instructed to stop, wait this long for
	// existing clients to finish before terminating.
	ShutdownTimeout time.Duration

	TLS      bool   // Starts with ListenAndServeTLS if true.
	CertFile string // If TLS == true, use this file for the certificate.
	KeyFile  string // If TLS == true, use this file for the key.
	// contains filtered or unexported fields
}

HTTP wraps a http.Server in a service.Service.

func NewHTTP

func NewHTTP(server *http.Server) *HTTP

func (*HTTP) Port

func (h *HTTP) Port() int

func (*HTTP) Run

func (h *HTTP) Run(ctx service.Context) (rerr error)

Run the HTTP server as a service.Service.

func (*HTTP) SetTLSCert

func (h *HTTP) SetTLSCert(certPem, keyPem []byte) error

SetTLSCertFile configures the HTTP server to use TLS with a cert and key supplied as byte arrays.

Any certificates set in Server.TLSConfig, or set in CertFile/KeyFile are cleared.

func (*HTTP) SetTLSCertFile

func (h *HTTP) SetTLSCertFile(certFile, keyFile string)

SetTLSCertFile configures the HTTP server to use TLS with a cert file and a key file

Any certificates set in Server.TLSConfig are cleared.

type TimedRestart

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

TimedRestart is an experimental service.Runnable that wraps your service and restarts it if it ends prematurely after a specific interval.

It's intended to prototype a method for retrying failed connections or subprocesses.

The "Suspend" function may not work as desired; more testing is required.

func NewTimedRestart

func NewTimedRestart(runnable service.Runnable, timeout time.Duration, wait WaitCalc, options ...TimedRestartOption) *TimedRestart

NewTimedRestart creates a TimedRestart service. If you want to log errors, pass in a listener, otherwise pass nil.

func (*TimedRestart) Run

func (t *TimedRestart) Run(ctx service.Context) error

func (*TimedRestart) Running

func (t *TimedRestart) Running() bool

func (*TimedRestart) Starts

func (t *TimedRestart) Starts() uint64

func (*TimedRestart) Suspend

func (t *TimedRestart) Suspend(suspended bool) (changed bool)

Suspend instructs the service to halt and to not restart.

func (*TimedRestart) Suspended

func (t *TimedRestart) Suspended() (out bool)

type TimedRestartOption

type TimedRestartOption func(tr *TimedRestart)

func TimedRestartActive

func TimedRestartActive(active bool) TimedRestartOption

func TimedRestartLimit

func TimedRestartLimit(limit uint64) TimedRestartOption

func TimedRestartNotify

func TimedRestartNotify(r func(start uint64, err error)) TimedRestartOption

type WaitCalc

type WaitCalc func() time.Duration

func WaitFixed

func WaitFixed(d time.Duration) WaitCalc

Jump to

Keyboard shortcuts

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