gs_app

package
v1.2.0-rc Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gs_app provides a framework for building and managing Go-Spring applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	C gs.Container
	P *gs_conf.AppConfig

	Runners []AppRunner `autowire:"${spring.app.runners:=*?}"`
	Servers []AppServer `autowire:"${spring.app.servers:=*?}"`
	// contains filtered or unexported fields
}

App represents the core application, managing its lifecycle, configuration, and the injection of dependencies.

func NewApp

func NewApp() *App

NewApp creates and initializes a new application instance.

func (*App) Run

func (app *App) Run() error

Run starts the application and listens for termination signals (e.g., SIGINT, SIGTERM). When a signal is received, it shuts down the application gracefully. Use ShutDown but not Stop to end the application lifecycle.

func (*App) ShutDown

func (app *App) ShutDown(msg ...string)

ShutDown gracefully terminates the application. It should be used when shutting down the application started by Run.

func (*App) Start

func (app *App) Start() error

Start initializes and starts the application. It loads configuration properties, refreshes the IoC container, performs dependency injection, and runs runners and servers.

func (*App) Stop

func (app *App) Stop()

Stop gracefully stops the application. This method is used to clean up resources and stop servers started by the Start method.

type AppContext

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

AppContext provides a wrapper around the application's gs.Context. It offers controlled access to the internal context and is designed to ensure safe usage in the application's lifecycle.

func (*AppContext) Go

func (p *AppContext) Go(fn func(ctx context.Context))

Go executes a function in a new goroutine. The provided function will receive a cancellation signal when the application begins shutting down.

func (*AppContext) Unsafe

func (p *AppContext) Unsafe() gs.Context

Unsafe exposes the underlying gs.Context. Using this method in new goroutines is unsafe because gs.Context may release its resources (e.g., bean definitions), making binding and injection operations invalid.

type AppRunner

type AppRunner interface {
	Run(ctx *AppContext)
}

AppRunner defines an interface for tasks that should be executed after all beans are injected but before the application's servers are started. It is commonly used to initialize background jobs or tasks.

type AppServer

type AppServer interface {
	OnAppStart(ctx *AppContext)
	OnAppStop(ctx context.Context)
}

AppServer defines an interface for managing the lifecycle of application servers, such as HTTP, gRPC, Thrift, or MQ servers. Servers must implement methods for starting and stopping gracefully.

type Boot

type Boot struct {
	Runners []AppRunner `autowire:"${spring.boot.runners:=*?}"`
	// contains filtered or unexported fields
}

Boot is the bootstrapper of the application.

func NewBoot

func NewBoot() *Boot

NewBoot creates a new Boot instance.

func (*Boot) Config

func (b *Boot) Config() *gs_conf.BootConfig

Config returns the boot configuration.

func (*Boot) GroupRegister

func (b *Boot) GroupRegister(fn func(p gs.Properties) ([]*gs.BeanDefinition, error))

GroupRegister registers a group of BeanDefinitions.

func (*Boot) Object

func (b *Boot) Object(i interface{}) *gs.RegisteredBean

Object registers an object bean.

func (*Boot) Provide

func (b *Boot) Provide(ctor interface{}, args ...gs.Arg) *gs.RegisteredBean

Provide registers a bean using a constructor function.

func (*Boot) Register

func (b *Boot) Register(bd *gs.BeanDefinition) *gs.RegisteredBean

Register registers a BeanDefinition instance.

func (*Boot) Run

func (b *Boot) Run() error

Run executes the application's bootstrap process.

func (*Boot) Runner added in v1.2.5

func (b *Boot) Runner(objOrCtor interface{}, ctorArgs ...gs.Arg) *gs.RegisteredBean

Runner registers an AppRunner instance.

Jump to

Keyboard shortcuts

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