ygg

package module
v0.0.0-...-67d1d53 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 16 Imported by: 0

README

Yggdrasil

Yggdrasil the base of all life (backend services).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Liveness

func Liveness() http.HandlerFunc

func NewCronComponent

func NewCronComponent(cron *gocron.Scheduler) *cronComponent

func NewHealthzComponent

func NewHealthzComponent(providers []Provider, config config.HealthzConfig) *healthzComponent

func NewLifecycleComponent

func NewLifecycleComponent(startups []LifeCycleFunc, run LifeCycleFunc, cleanups []LifeCycleFunc) *lifecycleComponent

func NewMetriczComponent

func NewMetriczComponent(registry *prometheus.Registry, config config.MetricszConfig) *metriczComponent

func WithHttpServer

func WithHttpServer(httpServer *http.Server) httpComponentOption

func WithServerConfig

func WithServerConfig(serverConfig *config.ServerConfig) httpComponentOption

Types

type Application

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

func NewApplications

func NewApplications(components ...Component) *Application

func (*Application) AddComponent

func (app *Application) AddComponent(c Component)

func (*Application) Run

func (app *Application) Run() error

func (Application) WithLogger

func (app Application) WithLogger(logger Logger) Application

func (Application) WithTimeout

func (app Application) WithTimeout(timeout time.Duration) Application

type Checkable

type Checkable interface {
	Healthz(ctx context.Context) error
}

Checkable Makes sure the object has the ) function

type CheckableFunc

type CheckableFunc func(ctx context.Context) error

func (CheckableFunc) Healthz

func (f CheckableFunc) Healthz(ctx context.Context) error

type Component

type Component interface {
	// Synchronous startup, container runs this one by one
	Startup() error
	// Asynchronous run,  container runs this in parrallel
	// Has to block until it's done
	// When one of componenst exits this func, container will start shutting down
	Run() error
	// Cleanup function
	Close(ctx context.Context) error
	// Retrieve hook functions
	Hooks() []Hook
}

type Error

type Error struct {
	Name    string `json:"name"`
	Message string `json:"message"`
}

Error the structure of the Error object

type HealthzChecker

type HealthzChecker struct {
	Providers []Provider
}

HealthzChecker contains the instance

func NewHealthChecker

func NewHealthChecker(providers []Provider) *HealthzChecker

func (*HealthzChecker) Healthz

func (h *HealthzChecker) Healthz() http.HandlerFunc

returns a http.HandlerFunc for the healthz service

func (*HealthzChecker) Serve

func (h *HealthzChecker) Serve(config config.HealthzConfig) *http.Server

type HealthzResponse

type HealthzResponse struct {
	Services []Service `json:"services,omitempty"`
	Healthy  bool      `json:"healthy"`
}

Response type, we return a json object with {healthy:bool, errors:[]}

type Hook

type Hook interface {
	Type() HookType
	Run() error
}

type HookType

type HookType = uint
const (
	HookTypeBeforeStartup HookType = iota
	HookTypeAfterStartup

	HookTypeBeforeRun
	HookTypeAfterRun

	HookTypeBeforeClose
)

type HttpComponent

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

func NewHttpComponent

func NewHttpComponent(handler http.Handler, options ...httpComponentOption) *HttpComponent

func (*HttpComponent) Close

func (hc *HttpComponent) Close(ctx context.Context) error

func (*HttpComponent) GetHandler

func (hc *HttpComponent) GetHandler(t testing.TB) http.Handler

This is just for testing

func (*HttpComponent) Hooks

func (hc *HttpComponent) Hooks() []Hook

func (*HttpComponent) Run

func (hc *HttpComponent) Run() error

func (*HttpComponent) Startup

func (hc *HttpComponent) Startup() error

type LifeCycleFunc

type LifeCycleFunc func(ctx context.Context) error

type Logger

type Logger interface {
	Debug(mgs string, params ...any)
	Info(mgs string, params ...any)
}

type Provider

type Provider struct {
	Handle Checkable
	Name   string
}

Provider is a provder we can check for healthz

type Service

type Service struct {
	Name         string `json:"name"`
	Healthy      bool   `json:"healthy"`
	ErrorMessage string `json:"error_message,omitempty"`
}

Service struct reprecenting a healthz provider and it's status

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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