gs

package
v1.2.2-rc Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 19 Imported by: 36

Documentation

Index

Constants

View Source
const (
	Version = "go-spring@v1.2.0"
	Website = "https://go-spring.com/"
)
View Source
const (
	AllowCircularReferencesProp = "spring.allow-circular-references"
	ForceAutowireIsNullableProp = "spring.force-autowire-is-nullable"
	ActiveProfilesProp          = "spring.profiles.active"
	EnableJobsProp              = "spring.app.enable-jobs"
	EnableServersProp           = "spring.app.enable-servers"
	EnableSimpleHttpServerProp  = "spring.enable.simple-http-server"
	EnableSimplePProfServerProp = "spring.enable.simple-pprof-server"
)

Variables

Functions

func AllowCircularReferences added in v1.2.0

func AllowCircularReferences(enable bool)

AllowCircularReferences enables or disables circular references between beans.

func As added in v1.2.0

func As[T any]() reflect.Type

As returns the reflect.Type of the given 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 returns a BindArg for the specified function and arguments. Used to provide argument binding for option-style constructor parameters.

func Component added in v1.2.0

func Component[T any](i T) T

Component registers a bean definition for a given object.

func Config added in v1.2.0

func Config() *gs_conf.AppConfig

Config returns the app configuration.

func EnableJobs added in v1.2.0

func EnableJobs(enable bool)

EnableJobs enables or disables the app jobs.

func EnableServers added in v1.2.0

func EnableServers(enable bool)

EnableServers enables or disables the app servers.

func EnableSimpleHttpServer added in v1.2.0

func EnableSimpleHttpServer(enable bool)

EnableSimpleHttpServer enables or disables the simple HTTP server.

func EnableSimplePProfServer added in v1.2.0

func EnableSimplePProfServer(enable bool)

EnableSimplePProfServer enables or disables the simple pprof server.

func Exiting added in v1.2.0

func Exiting() bool

Exiting returns a boolean indicating whether the application is exiting.

func ForceAutowireIsNullable added in v1.2.0

func ForceAutowireIsNullable(enable bool)

ForceAutowireIsNullable forces autowire to be nullable.

func GroupRegister added in v1.2.0

func GroupRegister(fn func(p conf.Properties) ([]*BeanDefinition, error))

GroupRegister registers a group of bean definitions.

func NewBean

func NewBean(objOrCtor any, ctorArgs ...gs.Arg) *gs.BeanDefinition

NewBean creates a new BeanDefinition.

func OnProperty

func OnProperty(name string) gs_cond.OnPropertyInterface

OnProperty creates a Condition based on a property name and options.

func Property

func Property(key string, val string)

Property sets a system property.

func RefreshProperties added in v1.2.0

func RefreshProperties() error

RefreshProperties refreshes the app configuration.

func RegisterExpressFunc added in v1.2.0

func RegisterExpressFunc(name string, fn any)

RegisterExpressFunc registers a custom expression function.

func Run

func Run()

Run runs the app and waits for an interrupt signal to exit.

func RunAsync

func RunAsync() (func(), error)

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

func RunWith

func RunWith(fn func(ctx context.Context) error)

RunWith runs the app with a given function and waits for an interrupt signal to exit.

func SetActiveProfiles added in v1.2.0

func SetActiveProfiles(profiles string)

SetActiveProfiles sets the active profiles for the app.

func ShutDown

func ShutDown()

ShutDown shuts down the app with an optional message.

Types

type AppStarter added in v1.2.0

type AppStarter struct{}

func Web

func Web(enable bool) *AppStarter

Web enables or disables the built-in web server.

func (*AppStarter) Run added in v1.2.0

func (s *AppStarter) Run()

Run runs the app and waits for an interrupt signal to exit.

func (*AppStarter) RunAsync

func (s *AppStarter) RunAsync() (func(), error)

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

func (*AppStarter) RunWith

func (s *AppStarter) RunWith(fn func(ctx context.Context) error)

RunWith runs the app with a given function and waits for an interrupt signal to exit.

type Arg added in v1.2.0

type Arg = gs.Arg

func IndexArg added in v1.2.0

func IndexArg(n int, arg Arg) Arg

IndexArg returns an IndexArg with the specified index and argument. When most constructor parameters can use default values, IndexArg helps reduce configuration effort.

func TagArg added in v1.2.0

func TagArg(tag string) Arg

TagArg returns a TagArg with the specified tag. Used for property binding or object injection when providing constructor parameters.

func ValueArg added in v1.2.0

func ValueArg(v any) Arg

ValueArg returns a ValueArg with the specified value. Used to provide specific values for constructor parameters.

type BeanDefinition

type BeanDefinition = gs.BeanDefinition

type BeanDestroyFunc added in v1.2.0

type BeanDestroyFunc = gs.BeanDestroyFunc

type BeanID added in v1.1.1

type BeanID = gs.BeanID

type BeanInitFunc added in v1.2.0

type BeanInitFunc = gs.BeanInitFunc

type BeanMock added in v1.2.0

type BeanMock = gs.BeanMock

type BeanSelector added in v1.2.0

type BeanSelector = gs.BeanSelector

func BeanSelectorFor added in v1.2.0

func BeanSelectorFor[T any](name ...string) BeanSelector

BeanSelectorFor returns a BeanSelector for the given type.

type CondContext added in v1.2.0

type CondContext = gs.CondContext

type Condition added in v1.2.0

type Condition = gs.Condition

func And added in v1.2.0

func And(conditions ...Condition) Condition

And creates a Condition that is true if all the given Conditions are true.

func None added in v1.2.0

func None(conditions ...Condition) Condition

None creates a Condition that is true if none of the given Conditions are true.

func Not added in v1.2.0

func Not(c Condition) Condition

Not creates a Condition that negates the given Condition.

func OnBean added in v1.2.0

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

OnBean creates a Condition for when a specific bean exists.

func OnExpression added in v1.2.0

func OnExpression(expression string) Condition

OnExpression creates a Condition based on a custom expression.

func OnFunc added in v1.2.0

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

OnFunc creates a Condition based on the provided function.

func OnMissingBean added in v1.2.0

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

OnMissingBean creates a Condition for when a specific bean is missing.

func OnMissingProperty added in v1.2.0

func OnMissingProperty(name string) Condition

OnMissingProperty creates a Condition that checks for a missing property.

func OnSingleBean added in v1.2.0

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

OnSingleBean creates a Condition for when only one instance of a bean exists.

func Or added in v1.2.0

func Or(conditions ...Condition) Condition

Or creates a Condition that is true if any of the given Conditions are true.

type Dync added in v1.2.0

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

type HttpServerConfig added in v1.2.0

type HttpServerConfig struct {
	Address       string        // The address to bind the server to.
	ReadTimeout   time.Duration // The read timeout duration.
	HeaderTimeout time.Duration // The header timeout duration.
	WriteTimeout  time.Duration // The write timeout duration.
	IdleTimeout   time.Duration // The idle timeout duration.
}

HttpServerConfig holds configuration options for the HTTP server.

type HttpServerOption added in v1.2.0

type HttpServerOption func(arg *HttpServerConfig)

HttpServerOption is a function type for setting options on HttpServerConfig.

func SetHttpServerAddr added in v1.2.0

func SetHttpServerAddr(addr string) HttpServerOption

SetHttpServerAddr sets the address of the HTTP server.

func SetHttpServerHeaderTimeout

func SetHttpServerHeaderTimeout(timeout time.Duration) HttpServerOption

SetHttpServerHeaderTimeout sets the header timeout for the HTTP server.

func SetHttpServerIdleTimeout

func SetHttpServerIdleTimeout(timeout time.Duration) HttpServerOption

SetHttpServerIdleTimeout sets the idle timeout for the HTTP server.

func SetHttpServerReadTimeout added in v1.2.0

func SetHttpServerReadTimeout(timeout time.Duration) HttpServerOption

SetHttpServerReadTimeout sets the read timeout for the HTTP server.

func SetHttpServerWriteTimeout added in v1.2.0

func SetHttpServerWriteTimeout(timeout time.Duration) HttpServerOption

SetHttpServerWriteTimeout sets the write timeout for the HTTP server.

type Job added in v1.2.0

type Job = gs.Job

type ReadySignal added in v1.2.0

type ReadySignal = gs.ReadySignal

type RegisteredBean added in v1.2.0

type RegisteredBean = gs.RegisteredBean

func FuncJob added in v1.2.0

func FuncJob(fn func(ctx context.Context) error) *RegisteredBean

FuncJob creates a Job from a function.

func FuncRunner added in v1.2.0

func FuncRunner(fn func() error) *RegisteredBean

FuncRunner creates a Runner from a function.

func Object

func Object(i any) *RegisteredBean

Object registers a bean definition for a given object.

func Provide

func Provide(ctor any, args ...Arg) *RegisteredBean

Provide registers a bean definition for a given constructor.

func Register added in v1.2.0

func Register(b *BeanDefinition) *RegisteredBean

Register registers a bean definition.

type Runner added in v1.2.0

type Runner = gs.Runner

type Server added in v1.2.0

type Server = gs.Server

type SimpleHttpServer added in v1.2.0

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

SimpleHttpServer wraps a http.Server instance.

func NewSimpleHttpServer added in v1.2.0

func NewSimpleHttpServer(mux *http.ServeMux, opts ...HttpServerOption) *SimpleHttpServer

NewSimpleHttpServer creates a new instance of SimpleHttpServer.

func (*SimpleHttpServer) ListenAndServe added in v1.2.0

func (s *SimpleHttpServer) ListenAndServe(sig ReadySignal) error

ListenAndServe starts the HTTP server and listens for incoming connections.

func (*SimpleHttpServer) Shutdown added in v1.2.0

func (s *SimpleHttpServer) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the HTTP server with the given context.

type SimplePProfServer added in v1.2.0

type SimplePProfServer struct {
	*SimpleHttpServer
}

SimplePProfServer is a simple pprof server.

func NewSimplePProfServer added in v1.2.0

func NewSimplePProfServer(addr string) *SimplePProfServer

NewSimplePProfServer creates a new SimplePProfServer.

Directories

Path Synopsis
Package gstest provides unit testing utilities for dependency injection in Go-Spring framework.
Package gstest provides unit testing utilities for dependency injection in Go-Spring framework.
internal
gs
gs_arg
Package gs_arg provides implementation for function argument resolution and binding
Package gs_arg provides implementation for function argument resolution and binding
gs_bean
Package gs_bean provides core bean management for Go-Spring framework, featuring:
Package gs_bean provides core bean management for Go-Spring framework, featuring:
gs_cond
Package gs_cond provides conditional component registration for Go-Spring framework, offering runtime decision-making through various condition types.
Package gs_cond provides conditional component registration for Go-Spring framework, offering runtime decision-making through various condition types.
gs_conf
Package gs_conf provides hierarchical configuration management with multi-source support for Go-Spring framework.
Package gs_conf provides hierarchical configuration management with multi-source support for Go-Spring framework.
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 applications.
Package gs_dync provides dynamic configuration binding and refresh capabilities for Go applications.

Jump to

Keyboard shortcuts

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