gs

package
v1.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: Apache-2.0 Imports: 25 Imported by: 71

Documentation

Index

Constants

View Source
const (
	Version = "go-spring@v1.2.5"
	Website = "https://github.com/go-spring/"
)

Variables

This section is empty.

Functions

func As added in v1.2.0

func As[T any]() reflect.Type

As returns the reflect.Type of an interface T. T is expected to be an interface type.

func Banner(banner string)

Banner sets a custom app banner.

func BindArg added in v1.2.0

func BindArg(fn any, args ...Arg) *gs_arg.BindArg

BindArg binds arguments dynamically to an option-style constructor.

func Group added in v1.2.3

func Group[T any, R any](tag string, fn func(c T) (R, error), d func(R) error)

Group registers a set of beans based on a configuration property map. Each map entry spawns a bean constructed via fn and optionally destroyed via d. The bean name is derived from the map key.

func Module added in v1.2.3

func Module(c PropertyCondition, fn ModuleFunc)

Module registers a configuration module that is conditionally activated based on property values.

func Provide

func Provide(objOrCtor any, args ...Arg) *gs_bean.BeanDefinition

Provide registers a global bean definition. It must be called during package initialization (init phase). Calling it after application configuration has started will panic. It accepts either an existing instance or a constructor function. The optional args are used to bind parameters for the constructor or to provide explicit injection values.

func RegisterExpressFunc added in v1.2.0

func RegisterExpressFunc(name string, fn any)

RegisterExpressFunc registers a custom expression function that can be used inside conditional expressions. It should be called during application initialization.

func Run

func Run() error

Run creates and starts a new application using default settings.

func RunAsync added in v1.2.2

func RunAsync(i any) (stop func(), err error)

RunAsync runs the application asynchronously and returns a function to stop the application.

func RunTest added in v1.3.0

func RunTest(t *testing.T, f any)

RunTest runs a test function using a new application instance. The test function must accept exactly one argument, which must be a pointer to a struct. The struct will be managed as a root bean in the application context.

Types

type App

type App interface {
	// Property sets a key-value property in the application configuration.
	Property(key string, val string)
	// Provide registers an object or constructor as a bean in the application.
	Provide(objOrCtor any, args ...gs.Arg) *gs_bean.BeanDefinition
}

App defines the configuration interface of a Go-Spring application. Methods on App are only valid during application configuration and must not be called after the application has started.

type AppStarter added in v1.2.0

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

AppStarter wraps a gs_app.App and manages its lifecycle. It provides methods for initialization, configuration, starting, stopping, running, and testing the application.

func Configure added in v1.3.0

func Configure(cfg func(App)) *AppStarter

Configure creates a new application and registers a configuration function that will be applied before the application starts.

func (*AppStarter) Run added in v1.2.0

func (s *AppStarter) Run() error

Run starts the application, applies configuration, and waits for termination signals (e.g., SIGTERM, Ctrl+C) to trigger a graceful shutdown. If no servers are running, the application stops immediately.

func (*AppStarter) RunAsync added in v1.2.2

func (s *AppStarter) RunAsync(i any) (stop func(), err error)

RunAsync runs the application asynchronously and returns a function to stop the application.

func (*AppStarter) RunTest added in v1.3.0

func (s *AppStarter) RunTest(t *testing.T, f any)

RunTest runs a user-defined test function with a provided test object. It initializes the application, registers the test object as a bean, starts the application, executes the test, and ensures graceful shutdown.

type Arg added in v1.2.0

type Arg = gs.Arg

Arg represents an argument used when binding constructor parameters.

func IndexArg added in v1.2.0

func IndexArg(n int, arg Arg) Arg

IndexArg targets a specific constructor parameter by index and provides the given Arg as its value.

func TagArg added in v1.2.0

func TagArg(tag string) Arg

TagArg creates an argument that injects a property or bean identified by the specified struct-tag expression.

func ValueArg added in v1.2.0

func ValueArg(v any) Arg

ValueArg creates an argument with a fixed value.

type BeanID added in v1.1.1

type BeanID = gs.BeanID

BeanID represents a selector for a bean.

type BeanProvider added in v1.3.0

type BeanProvider = gs_init.BeanProvider

type Condition added in v1.2.0

type Condition = gs.Condition

Condition represents a logical predicate that decides whether a bean or module should be activated.

func And added in v1.2.0

func And(conditions ...Condition) Condition

And combines multiple conditions using logical AND.

func None added in v1.2.0

func None(conditions ...Condition) Condition

None returns a condition that is true if all provided conditions are false.

func Not added in v1.2.0

func Not(c Condition) Condition

Not returns the logical negation of the given condition.

func OnBean added in v1.2.0

func OnBean[T any](name ...string) Condition

OnBean requires that a bean of the given type (and optional name) exists.

func OnExpression added in v1.2.0

func OnExpression(expression string) Condition

OnExpression creates a condition from an expression.

func OnFunc added in v1.2.0

func OnFunc(fn func(ctx ConditionContext) (bool, error)) Condition

OnFunc creates a Condition backed by the given function.

func OnMissingBean added in v1.2.0

func OnMissingBean[T any](name ...string) Condition

OnMissingBean requires that no bean of the given type (and optional name) exists.

func OnOnce added in v1.2.3

func OnOnce(conditions ...Condition) Condition

OnOnce wraps the given conditions so they are evaluated only once. Subsequent calls return the same result. (Not concurrency-safe.)

func OnSingleBean added in v1.2.0

func OnSingleBean[T any](name ...string) Condition

OnSingleBean requires that exactly one instance of the given bean type exists.

func Or added in v1.2.0

func Or(conditions ...Condition) Condition

Or combines multiple conditions using logical OR.

type ConditionContext added in v1.2.3

type ConditionContext = gs.ConditionContext

ConditionContext provides the evaluation context for a Condition.

type ContextAware added in v1.1.1

type ContextAware = gs_app.ContextAware

type Dync added in v1.2.0

type Dync[T any] = gs_dync.Value[T]

Dync is a generic alias for a dynamic configuration value. It represents a property that can change at runtime.

type HttpServeMux added in v1.3.0

type HttpServeMux struct {
	http.Handler
}

HttpServeMux is a lightweight wrapper around an http.Handler, allowing the default http.ServeMux or a custom handler to be injected into the HTTP server.

type ModuleFunc added in v1.3.0

type ModuleFunc = gs_init.ModuleFunc

ModuleFunc defines the signature of a module function.

type PropertyCondition added in v1.3.0

type PropertyCondition = gs_cond.PropertyCondition

PropertyCondition is a convenience wrapper for property-based conditions.

func OnProperty

func OnProperty(name string) PropertyCondition

OnProperty creates a property-based condition.

type ReadySignal added in v1.2.0

type ReadySignal = gs_app.ReadySignal

type Runner added in v1.2.0

type Runner = gs_app.Runner

type Server added in v1.2.0

type Server = gs_app.Server

type SimpleHttpServer added in v1.2.0

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

SimpleHttpServer wraps a standard http.Server to integrate it into the Go-Spring application lifecycle.

func NewSimpleHttpServer added in v1.2.0

func NewSimpleHttpServer(h *HttpServeMux, cfg SimpleHttpServerConfig) *SimpleHttpServer

NewSimpleHttpServer constructs a new SimpleHttpServer using the provided HTTP handler and configuration.

func (*SimpleHttpServer) Run added in v1.3.0

Run starts the HTTP server and blocks until it is stopped. It listens on the configured address immediately, but waits for the given ReadySignal before accepting traffic.

func (*SimpleHttpServer) Stop added in v1.3.0

func (s *SimpleHttpServer) Stop() error

Stop gracefully stops the HTTP server, allowing in-flight requests to complete.

type SimpleHttpServerConfig added in v1.2.4

type SimpleHttpServerConfig struct {
	// Address specifies the TCP address the server listens on.
	// Example: ":9090" (listen on all interfaces, port 9090).
	Address string `value:"${http.server.addr:=:9090}"`

	// ReadTimeout is the maximum duration for reading the entire
	// HTTP request, including the body.
	ReadTimeout time.Duration `value:"${http.server.readTimeout:=5s}"`

	// HeaderTimeout is the maximum duration for reading request headers.
	HeaderTimeout time.Duration `value:"${http.server.headerTimeout:=1s}"`

	// WriteTimeout is the maximum duration before timing out
	// an HTTP response write.
	WriteTimeout time.Duration `value:"${http.server.writeTimeout:=5s}"`

	// IdleTimeout is the maximum time to wait for the next request
	// when keep-alive connections are enabled.
	IdleTimeout time.Duration `value:"${http.server.idleTimeout:=60s}"`
}

SimpleHttpServerConfig holds configuration for SimpleHttpServer.

Directories

Path Synopsis
internal
gs
gs_arg
Package gs_arg provides implementations for argument resolution and binding used by the Go-Spring framework.
Package gs_arg provides implementations for argument resolution and binding used by the Go-Spring framework.
gs_bean
Package gs_bean provides core bean management for Go-Spring framework.
Package gs_bean provides core bean management for Go-Spring framework.
gs_cond
Package gs_cond provides a set of composable conditions used to control bean registration for Go-Spring framework.
Package gs_cond provides a set of composable conditions used to control bean registration for Go-Spring framework.
gs_conf
Package gs_conf provides a layered configuration system for Go-Spring applications.
Package gs_conf provides a layered configuration system for Go-Spring applications.
gs_core
Package gs_core provides the core implementation of the Inversion of Control (IoC) container in the Go-Spring framework.
Package gs_core provides the core implementation of the Inversion of Control (IoC) container in the Go-Spring framework.
gs_dync
Package gs_dync provides dynamic configuration binding and refresh capabilities for Go-Spring applications.
Package gs_dync provides dynamic configuration binding and refresh capabilities for Go-Spring applications.

Jump to

Keyboard shortcuts

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