Go-Spring
vision is to empower Go programmers with a powerful programming framework similar to Java Spring
. It is dedicated to providing users with a simple, secure, and reliable programming experience.
This project based from go-spring/go-spring created by lvan100
- Switch to monolithic repository.
- Remove third-party modules and retain only the core dependency injection functionality.
- Invoke
AppRunner
andAppEvent
in the order of their dependencies. - Add the dynamic property types like
Array
/Map
/Value
. - Add named logger.
In addition to implementing a powerful IoC container similar to Java Spring, Go-Spring also extends the concept of beans. In Go, objects (pointers), arrays, maps, and function pointers can all be considered beans and can be placed in the IoC container.
Java Spring | Go-Spring |
---|---|
@Value |
value:"${}" |
@Autowired @Qualifier @Required |
autowire:"?" |
@Configurable |
WireBean() |
@Profile |
ConditionOnProfile() |
@Primary |
Primary() |
@DependsOn |
DependsOn() |
@ConstructorBinding |
RegisterBeanFn() |
@ComponentScan @Indexed |
Package Import |
@Conditional |
NewConditional() |
@ConditionalOnExpression |
NewExpressionCondition() |
@ConditionalOnProperty |
NewPropertyValueCondition() |
@ConditionalOnBean |
NewBeanCondition() |
@ConditionalOnMissingBean |
NewMissingBeanCondition() |
@ConditionalOnClass |
Don't Need |
@ConditionalOnMissingClass |
Don't Need |
@Lookup |
—— |
Go-Spring
not only supports property binding for primitive data types but also supports property binding for custom value types. It also provides support for nested binding of struct properties.
type DB struct {
UserName string `value:"${username}"`
Password string `value:"${password}"`
Url string `value:"${url}"`
Port string `value:"${port}"`
DB string `value:"${db}"`
}
type DbConfig struct {
DB []DB `value:"${db}"`
}
The above code can be bound using the following configuration:
db:
-
username: root
password: 123456
url: 1.1.1.1
port: 3306
db: db1
-
username: root
password: 123456
url: 1.1.1.1
port: 3306
db: db2
The Go-Spring
is released under version 2.0 of the Apache License.