lifecycler

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package lifecycler helps Caddy modules manage the life cycle of submodules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaddyfileInfo

type CaddyfileInfo struct {
	ModuleID           []string              // module.id.path. with dot at end if required
	Raw                *[]json.RawMessage    // Where the raw config of submodules will be appended to
	SubModuleSpecifier string                // The specifier used by caddy to determine the submodule.
	ParseVerbLine      caddyfile.Unmarshaler // An optional [caddyfile.Unmarshaler]. If specified will be used to decode the second item on the first line of the config.
}

CaddyfileInfo is used to help unmarshal a caddyfile.

type LifeCyclable

type LifeCyclable[T any] interface {
	caddy.Module
	Start(T) error
}

LifeCyclable is a submodule that can be started.

type LifeCycler

type LifeCycler[T any] struct {
	V       T                 // Value passed to submodules
	Modules []LifeCyclable[T] // Unstarted submodules
	Started []LifeCyclable[T] // Started submodules
}

LifeCycler assists with loading submodules and maintaining their lifecycle.

func (*LifeCycler[T]) Cleanup added in v0.0.3

func (l *LifeCycler[T]) Cleanup() (err error)

Cleanup clears the lifecycler struct to help the GC. Any caddy submodules will be cleaned up by caddy.

func (*LifeCycler[T]) MarshalJSON

func (*LifeCycler[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns an error preventing LifeCycler from being used in configuration.

func (*LifeCycler[T]) Provision

func (l *LifeCycler[T]) Provision(ctx caddy.Context, info *ProvisionInfo) error

Provision loads submodules from the config. `info` must not be nil and the `Raw` field must be set.

func (*LifeCycler[T]) SetValue

func (l *LifeCycler[T]) SetValue(v T)

SetValue sets the internal value that will be passed to submodules.

func (*LifeCycler[T]) Start

func (l *LifeCycler[T]) Start() error

Start starts submodules and passes the stored value into them.

func (*LifeCycler[T]) UnmarshalCaddyfile

func (l *LifeCycler[T]) UnmarshalCaddyfile(d *caddyfile.Dispenser, info *CaddyfileInfo) error

UnmarshalCaddyfile unmarshals a module from a caddyfile. `info` must not be nil and must have the `raw` and `SubModuleSpecifier` fields set.

{
  <verb> [rest of line] {
    <submodule name> <submodule config>
  }
}

func (*LifeCycler[T]) UnmarshalJSON

func (*LifeCycler[T]) UnmarshalJSON([]byte) error

UnmarshalJSON returns an error preventing LifeCycler from being used in configuration.

type ProvisionInfo

type ProvisionInfo struct {
	StructPointer any                // Pointer to the struct to load config into
	FieldName     string             // Name of the field that config will be loaded into
	Raw           *[]json.RawMessage // Pointer to the array that config will be loaded into
}

ProvisionInfo is used to help with caddy provisioning.

Jump to

Keyboard shortcuts

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