Categorygithub.com/limpo1989/go-spring
repository
0.0.0-20230920040335-bd77e7c9ffe9
Repository: https://github.com/limpo1989/go-spring.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

Go-Spring

GoDoc license-Apache 2

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 and AppEvent in the order of their dependencies.
  • Add the dynamic property types like Array/Map/Value.
  • Add named logger.

IoC container

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 SpringGo-Spring
@Valuevalue:"${}"
@Autowired @Qualifier @Requiredautowire:"?"
@ConfigurableWireBean()
@ProfileConditionOnProfile()
@PrimaryPrimary()
@DependsOnDependsOn()
@ConstructorBindingRegisterBeanFn()
@ComponentScan @IndexedPackage Import
@ConditionalNewConditional()
@ConditionalOnExpressionNewExpressionCondition()
@ConditionalOnPropertyNewPropertyValueCondition()
@ConditionalOnBeanNewBeanCondition()
@ConditionalOnMissingBeanNewMissingBeanCondition()
@ConditionalOnClassDon't Need
@ConditionalOnMissingClassDon't Need
@Lookup——

Property binding

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

License

The Go-Spring is released under version 2.0 of the Apache License.