app

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

App

Your application runtime basis. Observes SIGINT and SIGTERM and calls lifecycle hooks.

Lifecycle

Use the app.Lifecycle struct to add lifecycle hooks to your application runtime. Register hooks using the OnStart and OnStop functions.

Runtime

Use the app.Runtime struct to start the applications lifecycle and listen to SIGINT and SIGTERM system events.

Usage

Example: a simple application using the fiber webserver.

File: src/app.go

package app

import (
	"github.com/Becklyn/go-wire-core/app"
	coreFiber "github.com/Becklyn/go-wire-core/fiber"
)

type AppOptions struct {
	Runtime         *app.Runtime
	UseFiberOptions *coreFiber.UseFiberOptions
}

type App struct {
	AppOptions
}

func newApp(options *AppOptions) *App {
	coreFiber.UseFiber(options.UseFiberOptions)

	return &App{
		*options,
	}
}

func (a *App) Run() {
	a.Runtime.Start()
}

File: src/app/wire.go

//go:build wireinject

package app

import (
	core "github.com/Becklyn/go-wire-core"
	"github.com/google/wire"
)

func New() *App {
	wire.Build(
		core.Default,
		wire.Struct(new(AppOptions), "*"),
		newApp,
	)
	return nil
}

File: src/main.go

package main

import (
	"github.com/your-app/src/app"
)

func main() {
	app.New().Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lifecycle

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

func NewLifecycle

func NewLifecycle() *Lifecycle

func (*Lifecycle) OnStart

func (l *Lifecycle) OnStart(hook LifecycleHook)

func (*Lifecycle) OnStop

func (l *Lifecycle) OnStop(hook LifecycleHook)

func (*Lifecycle) OnStopLast added in v1.4.0

func (l *Lifecycle) OnStopLast(hook LifecycleHook)

func (*Lifecycle) Start

func (l *Lifecycle) Start(ctx context.Context) error

func (*Lifecycle) Stop

func (l *Lifecycle) Stop() error

type LifecycleHook

type LifecycleHook func(ctx context.Context) error

type Runtime

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

func NewRuntime

func NewRuntime(lifecycle *Lifecycle, logger golog.Logger) *Runtime

func (*Runtime) Start

func (a *Runtime) Start()

Jump to

Keyboard shortcuts

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