service

package
v0.0.0-...-39eb377 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: ISC Imports: 29 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCfg

func LoadCfg(filePath string, templateData, dest interface{}) error

func LoadTemplates

func LoadTemplates(dirPath string, templateFunctions map[string]interface{}) (*texttemplate.Template, *htmltemplate.Template, error)

func RenderCfg

func RenderCfg(filePath string, templateContent []byte, templateData interface{}) ([]byte, error)

func Run

func Run(name, description string, implementation ServiceImplementation)

func RunTest

func RunTest(name string, implementation ServiceImplementation, cfgPath string, readyChan chan<- struct{})

func YAMLValueToJSONValue

func YAMLValueToJSONValue(yamlValue interface{}) (interface{}, error)

Types

type Service

type Service struct {
	Cfg *ServiceCfg
	Log *log.Logger

	Name           string
	Implementation ServiceImplementation

	Program *program.Program

	Hostname string

	Influx *influx.Client

	PgClients map[string]*pg.Client

	HTTPClients map[string]*shttp.Client
	HTTPServers map[string]*shttp.Server

	ServiceAPI *ServiceAPI

	Workers map[string]*Worker

	TextTemplate *texttemplate.Template
	HTMLTemplate *htmltemplate.Template
	// contains filtered or unexported fields
}

func (*Service) AddTemplateFunctions

func (s *Service) AddTemplateFunctions(functions map[string]interface{})

func (*Service) ErrorChan

func (s *Service) ErrorChan() chan<- error

func (*Service) HTTPClient

func (s *Service) HTTPClient(name string) *shttp.Client

func (*Service) HTTPServer

func (s *Service) HTTPServer(name string) *shttp.Server

func (*Service) PgClient

func (s *Service) PgClient(name string) *pg.Client

func (*Service) RenderHTMLTemplate

func (s *Service) RenderHTMLTemplate(name string, data interface{}) ([]byte, error)

func (*Service) RenderTextTemplate

func (s *Service) RenderTextTemplate(name string, data interface{}) ([]byte, error)

func (*Service) Stop

func (s *Service) Stop()

func (*Service) Worker

func (s *Service) Worker(name string) *Worker

type ServiceAPI

type ServiceAPI struct {
	Cfg     ServiceAPICfg
	Service *Service
	Log     *log.Logger

	HTTPServer *shttp.Server
}

func NewServiceAPI

func NewServiceAPI(cfg ServiceAPICfg) *ServiceAPI

func (*ServiceAPI) Start

func (s *ServiceAPI) Start() error

func (*ServiceAPI) Stop

func (s *ServiceAPI) Stop()

type ServiceAPICfg

type ServiceAPICfg struct {
	Log     *log.Logger `json:"-"`
	Service *Service    `json:"-"`

	HTTPServer string `json:"http_server"`
}

func (*ServiceAPICfg) ValidateJSON

func (cfg *ServiceAPICfg) ValidateJSON(v *ejson.Validator)

type ServiceCfg

type ServiceCfg struct {
	Logger *log.LoggerCfg `json:"logger"`

	DataDirectory string `json:"data_directory"`

	Influx *influx.ClientCfg `json:"influx"`

	PgClients map[string]*pg.ClientCfg `json:"pg_clients"`

	HTTPClients map[string]*shttp.ClientCfg `json:"http_clients"`
	HTTPServers map[string]*shttp.ServerCfg `json:"http_servers"`

	ServiceAPI *ServiceAPICfg `json:"service_api"`

	Workers map[string]*WorkerCfg `json:"workers"`

	TemplateFuncMap map[string]interface{} `json:"-"`
	// contains filtered or unexported fields
}

func (*ServiceCfg) ValidateJSON

func (cfg *ServiceCfg) ValidateJSON(v *ejson.Validator)

type ServiceImplementation

type ServiceImplementation interface {
	DefaultCfg() interface{}
	ValidateCfg() error
	ServiceCfg() *ServiceCfg
	Init(*Service) error
	Start(*Service) error
	Stop(*Service)
	Terminate(*Service)
}

type ServiceImplementationWithInitProgram

type ServiceImplementationWithInitProgram interface {
	ServiceImplementation

	InitProgram(*program.Program)
}

type Worker

type Worker struct {
	Cfg WorkerCfg
	Log *log.Logger
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(cfg WorkerCfg) (*Worker, error)

func (*Worker) Start

func (w *Worker) Start() error

func (*Worker) Stop

func (w *Worker) Stop()

type WorkerCfg

type WorkerCfg struct {
	Log          *log.Logger `json:"-"`
	WorkerFunc   WorkerFunc  `json:"-"`
	Disabled     bool        `json:"disabled"`
	InitialDelay int         `json:"initial_delay"` // seconds
}

type WorkerFunc

type WorkerFunc func(*Worker) (time.Duration, error)

Jump to

Keyboard shortcuts

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