Documentation
¶
Index ¶
- Constants
- Variables
- func AddTester(t any)
- func AllowCircularReferences(enable bool)
- func As[T any]() reflect.Type
- func Banner(banner string)
- func BindArg(fn any, args ...Arg) *gs_arg.BindArg
- func Config() *gs_conf.AppConfig
- func EnableJobs(enable bool)
- func EnableServers(enable bool)
- func EnableSimpleHttpServer(enable bool)
- func EnableSimplePProfServer(enable bool)
- func Exiting() bool
- func ForceAutowireIsNullable(enable bool)
- func Group[T any, R any](tag string, fn func(c T) (R, error), d func(R) error)
- func Job(fn func(ctx context.Context) error) *gs.RegisteredBean
- func Module(conditions []ConditionOnProperty, fn func(p conf.Properties) error)
- func Object(i any) *gs.RegisteredBean
- func Property(key string, val string)
- func Provide(ctor any, args ...Arg) *gs.RegisteredBean
- func RefreshProperties() error
- func RegisterExpressFunc(name string, fn any)
- func Root(b *gs.RegisteredBean)
- func Run(fn ...func() error)
- func RunAsync() (func(), error)
- func Runner(fn func() error) *gs.RegisteredBean
- func SetActiveProfiles(profiles string)
- func ShutDown()
- func TestMain(m *testing.M)
- type AppStarter
- type Arg
- type BeanMock
- type BeanSelector
- 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 ConditionOnProperty
- type Dync
- type ReadySignal
- type Server
- type SimpleHttpServer
- type SimpleHttpServerConfig
- type SimplePProfServer
Constants ¶
const ( Version = "go-spring@v1.2.5" Website = "https://github.com/go-spring/" )
const ( // AllowCircularReferencesProp controls whether the container // allows circular dependencies between beans. AllowCircularReferencesProp = "spring.allow-circular-references" // ForceAutowireIsNullableProp forces autowired dependencies // to be treated as nullable (i.e. allowed to be nil). ForceAutowireIsNullableProp = "spring.force-autowire-is-nullable" // ActiveProfilesProp defines the active application profiles // (e.g. "dev", "test", "prod"). ActiveProfilesProp = "spring.profiles.active" // EnableJobsProp enables or disables scheduled job execution. EnableJobsProp = "spring.app.enable-jobs" // EnableServersProp enables or disables all server components. EnableServersProp = "spring.app.enable-servers" // EnableSimpleHttpServerProp enables or disables the built-in // lightweight HTTP server. EnableSimpleHttpServerProp = "spring.enable.simple-http-server" // EnableSimplePProfServerProp enables or disables the built-in // lightweight pprof server. EnableSimplePProfServerProp = "spring.enable.simple-pprof-server" )
Variables ¶
var ( // B is the global bootstrapper for initializing the application. B = gs_app.NewBoot() )
Functions ¶
func AddTester ¶ added in v1.2.3
func AddTester(t any)
AddTester registers a tester instance into the test suite. The tester will be scanned for methods prefixed with "Test", which will be automatically added to the Go test framework.
func AllowCircularReferences ¶ added in v1.2.0
func AllowCircularReferences(enable bool)
AllowCircularReferences sets whether circular references between beans are permitted during dependency injection. Default is usually false.
func As ¶ added in v1.2.0
As returns the reflect.Type for a given interface type T.
func EnableJobs ¶ added in v1.2.0
func EnableJobs(enable bool)
EnableJobs enables or disables the execution of scheduled jobs.
func EnableServers ¶ added in v1.2.0
func EnableServers(enable bool)
EnableServers enables or disables all server components in the application (e.g. HTTP servers, gRPC servers).
func EnableSimpleHttpServer ¶ added in v1.2.0
func EnableSimpleHttpServer(enable bool)
EnableSimpleHttpServer enables or disables the built-in lightweight HTTP server provided by the framework.
func EnableSimplePProfServer ¶ added in v1.2.0
func EnableSimplePProfServer(enable bool)
EnableSimplePProfServer enables or disables the built-in lightweight pprof server for performance profiling.
func Exiting ¶ added in v1.2.0
func Exiting() bool
Exiting returns true if the application is shutting down.
func ForceAutowireIsNullable ¶ added in v1.2.0
func ForceAutowireIsNullable(enable bool)
ForceAutowireIsNullable forces autowired dependencies to be treated as optional (nullable). This allows injection of nil when no candidate bean is available. Default is usually false.
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.
func Job ¶ added in v1.2.0
func Job(fn func(ctx context.Context) error) *gs.RegisteredBean
Job registers a function as a job bean.
func Module ¶ added in v1.2.3
func Module(conditions []ConditionOnProperty, fn func(p conf.Properties) error)
Module registers a configuration module that is conditionally activated based on property values.
func Object ¶
func Object(i any) *gs.RegisteredBean
Object registers a bean definition for an existing object instance.
func Provide ¶
func Provide(ctor any, args ...Arg) *gs.RegisteredBean
Provide registers a bean definition using the provided constructor function.
func RefreshProperties ¶ added in v1.2.0
func RefreshProperties() error
RefreshProperties reloads application properties from all sources.
func RegisterExpressFunc ¶ added in v1.2.0
RegisterExpressFunc registers a custom expression function that can be used inside conditional expressions.
func Root ¶ added in v1.2.5
func Root(b *gs.RegisteredBean)
Root registers a root bean in the application context.
func RunAsync ¶ added in v1.2.2
func RunAsync() (func(), error)
RunAsync starts the application asynchronously and returns a stop function to gracefully shut it down.
func Runner ¶ added in v1.2.0
func Runner(fn func() error) *gs.RegisteredBean
Runner registers a function as a runner bean.
func SetActiveProfiles ¶ added in v1.2.0
func SetActiveProfiles(profiles string)
SetActiveProfiles sets the active application profiles (e.g. "dev", "prod"). This influences which configuration files and conditional beans are loaded.
Types ¶
type AppStarter ¶ added in v1.2.0
type AppStarter struct{}
AppStarter is a wrapper to manage the lifecycle of a Spring application. It handles initialization, running, graceful shutdown, and logging.
func (*AppStarter) Run ¶ added in v1.2.0
func (s *AppStarter) Run(fn ...func() error)
Run starts the application, optionally runs a user-defined callback, and waits for termination signals (e.g., SIGTERM, Ctrl+C) to trigger graceful shutdown.
func (*AppStarter) RunAsync ¶ added in v1.2.2
func (s *AppStarter) RunAsync() (func(), error)
RunAsync starts the application asynchronously and returns a function that can be used to trigger shutdown from outside.
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 BeanMock ¶ added in v1.2.0
type BeanMock[T any] struct { // contains filtered or unexported fields }
BeanMock represents a mock bean for testing.
type BeanSelector ¶ added in v1.2.0
type BeanSelector = gs.BeanSelector
BeanSelector is an alias for gs.BeanSelector used to locate beans within the ioc context.
func BeanSelectorFor ¶ added in v1.2.0
func BeanSelectorFor[T any](name ...string) BeanSelector
BeanSelectorFor creates a BeanSelector for the specified type T and optional bean name.
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 ConditionOnProperty ¶ added in v1.2.3
type ConditionOnProperty = gs_cond.ConditionOnProperty
ConditionOnProperty is a convenience wrapper for property-based conditions.
func OnEnableJobs ¶ added in v1.2.3
func OnEnableJobs() ConditionOnProperty
OnEnableJobs is a shortcut for checking whether scheduled jobs are enabled.
func OnEnableServers ¶ added in v1.2.3
func OnEnableServers() ConditionOnProperty
OnEnableServers is a shortcut for checking whether servers are enabled.
func OnProperty ¶
func OnProperty(name string) ConditionOnProperty
OnProperty creates a property-based condition.
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 ReadySignal ¶ added in v1.2.0
type ReadySignal = gs.ReadySignal
ReadySignal represents a signal sent when the application is ready.
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 http.Handler, cfg SimpleHttpServerConfig) *SimpleHttpServer
NewSimpleHttpServer constructs a new SimpleHttpServer using the provided HTTP handler and configuration.
func (*SimpleHttpServer) ListenAndServe ¶ added in v1.2.0
func (s *SimpleHttpServer) ListenAndServe(sig ReadySignal) error
ListenAndServe starts the HTTP server and blocks until it is stopped. It waits for the given ReadySignal to be triggered before accepting traffic.
type SimpleHttpServerConfig ¶ added in v1.2.5
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 // 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 // a response write. WriteTimeout time.Duration `value:"${http.server.writeTimeout:=5s}"` // IdleTimeout is the maximum amount of 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 the SimpleHttpServer.
type SimplePProfServer ¶ added in v1.2.0
type SimplePProfServer struct {
*SimpleHttpServer
}
SimplePProfServer is a simple HTTP server that exposes pprof endpoints.
func NewSimplePProfServer ¶ added in v1.2.0
func NewSimplePProfServer(addr string) *SimplePProfServer
NewSimplePProfServer creates a new SimplePProfServer at the given address. It registers the standard pprof handlers for runtime profiling and debugging.
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 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. |