Merge branch ‘go-spring:master’ into master
Go-Spring 的愿景是让 Go 程序员也能用上如 Java Spring 那般威力强大的编程框架。
其特性如下:
Go-Spring 当前使用 Go1.12 进行开发,使用 Go Modules 进行依赖管理。
Go-Spring 不仅实现了如 Java Spring 那般功能强大的 IoC 容器,还扩充了 Bean 的概念。在 Go 中,对象(即指针)、数组、Map、函数指针,这些都是 Bean,都可以放到 IoC 容器里。
@Value
value:"${}"
@Autowired
@Qualifier
@Required
autowire:"?"
@Configurable
WireBean()
@Profile
ConditionOnProfile()
@Primary
Primary()
@DependsOn
DependsOn()
@ConstructorBinding
RegisterBeanFn()
@ComponentScan
@Indexed
@Conditional
NewConditional()
@ConditionalOnExpression
NewExpressionCondition()
@ConditionalOnProperty
NewPropertyValueCondition()
@ConditionalOnBean
NewBeanCondition()
@ConditionalOnMissingBean
NewMissingBeanCondition()
@ConditionalOnClass
@ConditionalOnMissingClass
@Lookup
Go-Spring 不仅支持对普通数据类型进行属性绑定,也支持对自定义值类型进行属性绑定,而且还支持对结构体属性的嵌套绑定。
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}"` }
上面这段代码可以通过下面的配置进行绑定:
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
Go-Spring 提供了一个功能强大的启动器框架,不仅实现了自动加载、开箱即用,而且可以非常容易的开发自己的启动器模块,使得代码不仅仅是库层面的复用。
下面的示例使用 v1.0.5 版本测试通过。
import ( "context" "github.com/go-spring/spring-boot" _ "github.com/go-spring/starter-echo" ) func init() { SpringBoot.RegisterBean(new(Service)).Init(func(s *Service) { SpringBoot.GetBinding("/", s.Echo) }) } type Service struct { GoPath string `value:"${GOPATH}"` } type EchoRequest struct{} func (s *Service) Echo(ctx context.Context, req *EchoRequest) interface{} { return s.GoPath } func main() { SpringBoot.RunApplication() }
启动上面的程序,控制台输入 curl http://localhost:8080/, 可得到如下结果:
curl http://localhost:8080/
{"code":200,"msg":"SUCCESS","data":"/Users/didi/go"}
更多示例: https://github.com/go-spring/go-spring/tree/master/examples
https://docs.lavend.net/
@lvan100 (LiangHuan)
@CoderPoet 、@limpo1989
@shenqidebaozi
如何成为贡献者?提交有意义的 PR 或者需求,并被采纳。
The Go-Spring is released under version 2.0 of the Apache License.
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
Go-Spring 的愿景是让 Go 程序员也能用上如 Java Spring 那般威力强大的编程框架。
其特性如下:
Go-Spring 当前使用 Go1.12 进行开发,使用 Go Modules 进行依赖管理。
IoC 容器
Go-Spring 不仅实现了如 Java Spring 那般功能强大的 IoC 容器,还扩充了 Bean 的概念。在 Go 中,对象(即指针)、数组、Map、函数指针,这些都是 Bean,都可以放到 IoC 容器里。
@Valuevalue:"${}"@Autowired@Qualifier@Requiredautowire:"?"@ConfigurableWireBean()@ProfileConditionOnProfile()@PrimaryPrimary()@DependsOnDependsOn()@ConstructorBindingRegisterBeanFn()@ComponentScan@Indexed@ConditionalNewConditional()@ConditionalOnExpressionNewExpressionCondition()@ConditionalOnPropertyNewPropertyValueCondition()@ConditionalOnBeanNewBeanCondition()@ConditionalOnMissingBeanNewMissingBeanCondition()@ConditionalOnClass@ConditionalOnMissingClass@Lookup属性绑定
Go-Spring 不仅支持对普通数据类型进行属性绑定,也支持对自定义值类型进行属性绑定,而且还支持对结构体属性的嵌套绑定。
上面这段代码可以通过下面的配置进行绑定:
Boot 框架
Go-Spring 提供了一个功能强大的启动器框架,不仅实现了自动加载、开箱即用,而且可以非常容易的开发自己的启动器模块,使得代码不仅仅是库层面的复用。
快速示例
下面的示例使用 v1.0.5 版本测试通过。
启动上面的程序,控制台输入
curl http://localhost:8080/, 可得到如下结果:更多示例: https://github.com/go-spring/go-spring/tree/master/examples
详细文档
https://docs.lavend.net/
项目成员
发起者(负责人)
@lvan100 (LiangHuan)
优秀贡献者
@CoderPoet 、@limpo1989
特别鸣谢
@shenqidebaozi
如何成为贡献者?提交有意义的 PR 或者需求,并被采纳。
QQ 交流群
QQ群号:721077608
微信公众号
License
The Go-Spring is released under version 2.0 of the Apache License.