12
12
13
13
[ English] ( README.md ) | [ 中文] ( README_CN.md )
14
14
15
+ > The project has been officially released, welcome to use!
16
+
15
17
** Go-Spring is a high-performance framework for modern Go application development, inspired by the Spring / Spring Boot
16
18
ecosystem in the Java community.**
17
19
Its design philosophy deeply integrates the characteristics of the Go language, retaining mature development paradigms
@@ -105,8 +107,8 @@ func init() {
105
107
return http.DefaultServeMux
106
108
})
107
109
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))
110
112
}
111
113
```
112
114
@@ -126,7 +128,7 @@ func (s *Service) Echo(w http.ResponseWriter, r *http.Request) {
126
128
}
127
129
128
130
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))
130
132
gs.RefreshProperties ()
131
133
w.Write ([]byte (" OK!" ))
132
134
}
@@ -387,7 +389,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
387
389
}
388
390
389
391
func RefreshVersion (w http .ResponseWriter , r *http .Request ) {
390
- sysconf. Set (versionKey, " v2.0.1" )
392
+ gs. Property (versionKey, " v2.0.1" )
391
393
gs.RefreshProperties ()
392
394
fmt.Fprintln (w, " Version updated!" )
393
395
}
@@ -563,47 +565,7 @@ func init() {
563
565
564
566
## ⏳ Mock and Unit Testing
565
567
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
+ ...
607
569
608
570
## 📚 Comparison with Other Frameworks
609
571
0 commit comments