go-spring

module
v0.0.0-...-bd77e7c Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0

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 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 ——
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.

Directories

Path Synopsis
Package conf reads configuration from many format file, such as Java properties, yaml, toml, etc.
Package conf reads configuration from many format file, such as Java properties, yaml, toml, etc.
Package dync provide dynamic property supported.
Package dync provide dynamic property supported.
gs
Package gs is a core of Go-Spring, including IOC container, IOC container-based APP.
Package gs is a core of Go-Spring, including IOC container, IOC container-based APP.
arg
Package arg provide a method arguments binding。
Package arg provide a method arguments binding。
cond
Package cond provides many conditions used when registering bean.
Package cond provides many conditions used when registering bean.
internal
log
utils
Package util is a generated GoMock package.
Package util is a generated GoMock package.
utils/assert
Package assert provides some useful assertion methods.
Package assert provides some useful assertion methods.

Jump to

Keyboard shortcuts

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