Skip to content

Commit 39837af

Browse files
authored
Merge pull request #37 from lvan100/main
update version & remove gstest
2 parents 9f1e779 + 51550b8 commit 39837af

File tree

3 files changed

+15
-90
lines changed

3 files changed

+15
-90
lines changed

README.md

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
[English](README.md) | [中文](README_CN.md)
1414

15+
> The project has been officially released, welcome to use!
16+
1517
**Go-Spring is a high-performance framework for modern Go application development, inspired by the Spring / Spring Boot
1618
ecosystem in the Java community.**
1719
Its design philosophy deeply integrates the characteristics of the Go language, retaining mature development paradigms
@@ -105,8 +107,8 @@ func init() {
105107
return http.DefaultServeMux
106108
})
107109

108-
sysconf.Set("start-time", time.Now().Format(timeLayout))
109-
sysconf.Set("refresh-time", time.Now().Format(timeLayout))
110+
gs.Property("start-time", time.Now().Format(timeLayout))
111+
gs.Property("refresh-time", time.Now().Format(timeLayout))
110112
}
111113
```
112114

@@ -126,7 +128,7 @@ func (s *Service) Echo(w http.ResponseWriter, r *http.Request) {
126128
}
127129

128130
func (s *Service) Refresh(w http.ResponseWriter, r *http.Request) {
129-
sysconf.Set("refresh-time", time.Now().Format(timeLayout))
131+
gs.Property("refresh-time", time.Now().Format(timeLayout))
130132
gs.RefreshProperties()
131133
w.Write([]byte("OK!"))
132134
}
@@ -387,7 +389,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
387389
}
388390

389391
func RefreshVersion(w http.ResponseWriter, r *http.Request) {
390-
sysconf.Set(versionKey, "v2.0.1")
392+
gs.Property(versionKey, "v2.0.1")
391393
gs.RefreshProperties()
392394
fmt.Fprintln(w, "Version updated!")
393395
}
@@ -563,47 +565,7 @@ func init() {
563565

564566
## ⏳ Mock and Unit Testing
565567

566-
Go-Spring provides a unit testing framework that seamlessly integrates with the standard `go test`, making dependency
567-
injection and mock testing simple and efficient.
568-
569-
### 1. Mock Object Injection
570-
571-
Use `gstest.MockFor[T]().With(obj)` to easily replace any bean at runtime:
572-
573-
```go
574-
gstest.MockFor[*book_dao.BookDao]().With(&book_dao.BookDao{
575-
Store: map[string]book_dao.Book{
576-
"978-0132350884": {
577-
Title: "Clean Code",
578-
Author: "Robert C. Martin",
579-
ISBN: "978-0132350884",
580-
Publisher: "Prentice Hall",
581-
},
582-
},
583-
})
584-
```
585-
586-
### 2. Obtain Test Objects
587-
588-
There are two ways to obtain the object under test:
589-
590-
**Directly Get Instance**:
591-
592-
```go
593-
o := gstest.Get[*BookDao](t)
594-
assert.NotNil(t, o)
595-
```
596-
597-
**Structured Injection**:
598-
599-
```go
600-
s := gstest.Wire(t, new(struct {
601-
SvrAddr string `value:"${server.addr}"`
602-
Service *BookService `autowire:""`
603-
BookDao *book_dao.BookDao `autowire:""`
604-
}))
605-
assert.That(t, s.SvrAddr).Equal("0.0.0.0:9090")
606-
```
568+
...
607569

608570
## 📚 Comparison with Other Frameworks
609571

README_CN.md

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
[English](README.md) | [中文](README_CN.md)
1414

15+
> 该项目已经正式发布,欢迎使用!
16+
1517
**Go-Spring 是一个面向现代 Go 应用开发的高性能框架,灵感源自 Java 社区的 Spring / Spring Boot。**
1618
它的设计理念深度融合 Go 语言的特性,既保留了 Spring 世界中成熟的开发范式,如依赖注入(DI)、自动配置和生命周期管理,
1719
又避免了传统框架可能带来的繁复和性能开销。
@@ -96,8 +98,8 @@ func init() {
9698
return http.DefaultServeMux
9799
})
98100

99-
sysconf.Set("start-time", time.Now().Format(timeLayout))
100-
sysconf.Set("refresh-time", time.Now().Format(timeLayout))
101+
gs.Property("start-time", time.Now().Format(timeLayout))
102+
gs.Property("refresh-time", time.Now().Format(timeLayout))
101103
}
102104
```
103105

@@ -117,7 +119,7 @@ func (s *Service) Echo(w http.ResponseWriter, r *http.Request) {
117119
}
118120

119121
func (s *Service) Refresh(w http.ResponseWriter, r *http.Request) {
120-
sysconf.Set("refresh-time", time.Now().Format(timeLayout))
122+
gs.Property("refresh-time", time.Now().Format(timeLayout))
121123
gs.RefreshProperties()
122124
w.Write([]byte("OK!"))
123125
}
@@ -358,7 +360,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
358360
}
359361

360362
func RefreshVersion(w http.ResponseWriter, r *http.Request) {
361-
sysconf.Set(versionKey, "v2.0.1")
363+
gs.Property(versionKey, "v2.0.1")
362364
gs.RefreshProperties()
363365
fmt.Fprintln(w, "Version updated!")
364366
}
@@ -527,46 +529,7 @@ func init() {
527529

528530
## ⏳ Mock 与单元测试
529531

530-
Go-Spring 提供了与标准 `go test` 无缝集成的单元测试框架,让依赖注入和模拟测试变得简单高效。
531-
532-
### 1. 模拟对象注入
533-
534-
使用 `gstest.MockFor[T]().With(obj)` 可以在运行时轻松替换任何 bean:
535-
536-
```go
537-
gstest.MockFor[*book_dao.BookDao]().With(&book_dao.BookDao{
538-
Store: map[string]book_dao.Book{
539-
"978-0132350884": {
540-
Title: "Clean Code",
541-
Author: "Robert C. Martin",
542-
ISBN: "978-0132350884",
543-
Publisher: "Prentice Hall",
544-
},
545-
},
546-
})
547-
```
548-
549-
### 2. 获取测试对象
550-
551-
有两种方式获取被测试对象:
552-
553-
**直接获取实例**
554-
555-
```go
556-
o := gstest.Get[*BookDao](t)
557-
assert.NotNil(t, o)
558-
```
559-
560-
**结构化注入**
561-
562-
```go
563-
s := gstest.Wire(t, new(struct {
564-
SvrAddr string `value:"${server.addr}"`
565-
Service *BookService `autowire:""`
566-
BookDao *book_dao.BookDao `autowire:""`
567-
}))
568-
assert.That(t, s.SvrAddr).Equal("0.0.0.0:9090")
569-
```
532+
...
570533

571534
## 📚 与其他框架的对比
572535

gs/gs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
const (
36-
Version = "go-spring@v1.2.3"
36+
Version = "go-spring@v1.2.5"
3737
Website = "https://github.com/go-spring/"
3838
)
3939

0 commit comments

Comments
 (0)