Documentation
¶
Index ¶
- Constants
- func As[T any]() reflect.Type
- func Banner(banner string)
- func BindArg(fn any, args ...Arg) *gs_arg.BindArg
- func Group[T any, R any](tag string, fn func(c T) (R, error), d func(R) error)
- func Module(c PropertyCondition, fn ModuleFunc)
- func Provide(objOrCtor any, args ...Arg) *gs_bean.BeanDefinition
- func RegisterExpressFunc(name string, fn any)
- func Run()
- func RunAsync() (stop func(), err error)
- func RunTest(t *testing.T, f any)
- type App
- type AppStarter
- type Arg
- type BeanID
- type BeanProvider
- type Condition
- func And(conditions ...Condition) Condition
- func None(conditions ...Condition) Condition
- func Not(c Condition) Condition
- func OnBean[T any](name ...string) Condition
- func OnExpression(expression string) Condition
- func OnFunc(fn func(ctx ConditionContext) (bool, error)) Condition
- func OnMissingBean[T any](name ...string) Condition
- func OnOnce(conditions ...Condition) Condition
- func OnSingleBean[T any](name ...string) Condition
- func Or(conditions ...Condition) Condition
- type ConditionContext
- type ContextProvider
- type Dync
- type HttpServeMux
- type ModuleFunc
- type PropertiesRefresher
- type PropertyCondition
- type ReadySignal
- type Runner
- type Server
- type SimpleHttpServer
- type SimpleHttpServerConfig
Constants ¶
const ( Version = "go-spring@v1.3.0-rc" Website = "https://github.com/go-spring/" )
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v1.2.0
As returns the reflect.Type of an interface T. T is expected to be an interface type.
func Group ¶ added in v1.2.3
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
RegisterExpressFunc registers a custom expression function that can be used inside conditional expressions. It should be called during application initialization.
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
// Root marks a bean as the root bean.
Root(b *gs_bean.BeanDefinition) *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()
Run starts the application, applies configuration, and waits for termination signals (e.g., SIGTERM, Ctrl+C) to trigger a graceful shutdown.
func (*AppStarter) RunAsync ¶ added in v1.2.2
func (s *AppStarter) RunAsync() (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
Arg represents an argument used when binding constructor parameters.
func IndexArg ¶ added in v1.2.0
IndexArg targets a specific constructor parameter by index and provides the given Arg as its value.
type BeanProvider ¶ added in v1.3.0
type BeanProvider = gs_init.BeanProvider
type Condition ¶ added in v1.2.0
Condition represents a logical predicate that decides whether a bean or module should be activated.
func None ¶ added in v1.2.0
None returns a condition that is true if all provided conditions are false.
func OnBean ¶ added in v1.2.0
OnBean requires that a bean of the given type (and optional name) exists.
func OnExpression ¶ added in v1.2.0
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
OnMissingBean requires that no bean of the given type (and optional name) exists.
func OnOnce ¶ added in v1.2.3
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
OnSingleBean requires that exactly one instance of the given bean type exists.
type ConditionContext ¶ added in v1.2.3
type ConditionContext = gs.ConditionContext
ConditionContext provides the evaluation context for a Condition.
type ContextProvider ¶ added in v1.3.0
type ContextProvider = gs_app.ContextProvider
type Dync ¶ added in v1.2.0
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
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 PropertiesRefresher ¶ added in v1.3.0
type PropertiesRefresher = gs_app.PropertiesRefresher
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 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
func (s *SimpleHttpServer) Run(ctx context.Context, sig ReadySignal) error
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:"${addr:=:9090}"`
// ReadTimeout is the maximum duration for reading the entire
// HTTP request, including the body.
ReadTimeout time.Duration `value:"${readTimeout:=5s}"`
// HeaderTimeout is the maximum duration for reading request headers.
HeaderTimeout time.Duration `value:"${headerTimeout:=1s}"`
// WriteTimeout is the maximum duration before timing out
// an HTTP response write.
WriteTimeout time.Duration `value:"${writeTimeout:=5s}"`
// IdleTimeout is the maximum time to wait for the next request
// when keep-alive connections are enabled.
IdleTimeout time.Duration `value:"${idleTimeout:=60s}"`
}
SimpleHttpServerConfig holds configuration for SimpleHttpServer.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
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 used by the Go-Spring framework.
|
Package gs_core provides the core implementation of the Inversion of Control (IoC) container used by 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. |