lite

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0, MIT Imports: 6 Imported by: 0

README

Lite Go Reference

Lite is package contains compact version of squad with auto liveness and readiness checks.

Usage

package main

import (
	"context"
	"time"

	"github.com/moeryomenko/healing"
	"github.com/moeryomenko/healing/decorators/pgx"
	"github.com/moeryomenko/lite"
)

func main() {
	h := lite.New(8081 // health controller port.
		healing.WithCheckPeriod(3 * time.Second),
		healing.WithReadinessTimeout(time.Second),
		healing.WithReadyEndpoint("/readz"),
	)

	// create postgresql pool.
	pool, err := pgx.New(ctx, pgx.Config{
		Host:     pgHost,
		Port:     pgPort,
		User:     pgUser,
		Password: pgPassword,
		DBName:   pgName,
	}, pgx.WithHealthCheckPeriod(100 * time.Millisecond)) // sets the duration between checks of the health of idle conn.
	if err != nil {
		// error handling.
		...
	}

	// add pool readiness controller to readiness group.
	l.AddReadyChecker("pgx", pool.CheckReadinessProber)

    // Run your service.
	err = l.Run(svc.Run)
	// log err if service stopped with error.
}

License

Lite is primarily distributed under the terms of both the MIT license and Apache License (Version 2.0).

See LICENSE-APACHE and/or LICENSE-MIT for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDelay

func WithDelay(ctx context.Context, delay time.Duration) context.Context

Types

type Lite

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

Lite is compact squad implementation.

func New

func New(healthPort int, opts ...healing.Option) *Lite

New returns new instance of Lite.

func (*Lite) AddLiveCheck

func (l *Lite) AddLiveCheck(subsystem string, check func(context.Context) healing.CheckResult)

AddLiveCheck adds subsystem check for checks liveness.

func (*Lite) AddReadyCheck

func (l *Lite) AddReadyCheck(subsystem string, check func(context.Context) healing.CheckResult)

AddReadyCheck adds subsystem check for checks readiness.

func (*Lite) Run

func (l *Lite) Run(service func(context.Context) error) error

Run launch service and health controller.

Jump to

Keyboard shortcuts

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