Skip to content

Commit 46c908c

Browse files
lvan100lianghuan
authored andcommitted
Docs (internal): Add package comments
1 parent 7dba1c1 commit 46c908c

File tree

6 files changed

+173
-5
lines changed

6 files changed

+173
-5
lines changed

gs/gstest/gstest.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,36 @@
1414
* limitations under the License.
1515
*/
1616

17-
// Package gstest is a unit testing framework designed for dependency injection in go-spring.
18-
// Unlike standard dependency injection, in unit testing mode, the framework gracefully ignores
19-
// non-critical dependency injection failures by logging warnings instead of halting execution.
20-
// This ensures seamless testing workflows when dealing with extensive dependencies,
21-
// as only the specific dependencies under test need to be validated, while others remain non-blocking.
17+
/*
18+
Package gstest provides unit testing utilities for dependency injection in Go-Spring framework.
19+
20+
Key Features:
21+
- Non-critical Dependency Tolerance - Gracefully ignores non-test-target injection failures
22+
via warning logs (enabled by gs.ForceAutowireIsNullable)
23+
- Type-Safe Mocking - Offers MockFor/With methods for compile-time verified mock registration
24+
- Context Lifecycle Management - TestMain automates application context bootstrap/teardown
25+
- Smart Injection Helpers - Provides Get/Wire utilities to simplify test case composition
26+
27+
Usage Pattern:
28+
29+
// Register mocks in init function (executes before TestMain)
30+
func init() {
31+
gstest.MockFor[*Dao]().With(&MockDao{})
32+
}
33+
34+
func TestMain(m *testing.M) {
35+
gstest.TestMain(m)
36+
}
37+
38+
func TestService(t *testing.T) {
39+
// Retrieve autowired test target
40+
service := gstest.Get[*Service](t)
41+
42+
// Verify business logic
43+
result := service.Process()
44+
assert.Equal(t, expect, result)
45+
}
46+
*/
2247
package gstest
2348

2449
import (

gs/internal/gs_arg/arg.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
Package gs_arg provides implementation for function argument resolution and binding
19+
20+
Key Features:
21+
- Configuration property binding and dependency injection via struct tags
22+
- Precise positional binding through index-based arguments
23+
- Direct injection of fixed value arguments
24+
- Full support for variadic function parameters
25+
- Conditional execution with runtime evaluation
26+
*/
1727
package gs_arg
1828

1929
import (

gs/internal/gs_bean/bean.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
Package gs_bean provides core bean management for Go-Spring framework, featuring:
19+
20+
- Full lifecycle management (instantiation, DI, destruction)
21+
- Method-as-factory mechanism (generate child beans via configured rules)
22+
- Conditional registration (profile-based activation)
23+
- Type-safe interface export validation
24+
- Mock replacement mechanism
25+
*/
1726
package gs_bean
1827

1928
import (

gs/internal/gs_cond/cond.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
Package gs_cond provides conditional component registration for Go-Spring framework,
19+
offering runtime decision-making through various condition types.
20+
21+
1. Property Conditions
22+
23+
- Existence check:
24+
cond := OnProperty("db.host")
25+
26+
- Value matching:
27+
cond := OnProperty("env").HavingValue("prod")
28+
29+
- Expression evaluation:
30+
cond := OnProperty("port").HavingValue("expr:int($) > 1024")
31+
32+
- Missing handling:
33+
cond := OnProperty("debug").MatchIfMissing()
34+
35+
2. Bean Conditions
36+
37+
- Existence verification:
38+
cond := OnBean[Database]()
39+
40+
- Absence check:
41+
cond := OnMissingBean[Logger]()
42+
43+
- Singleton validation:
44+
cond := OnSingleBean[Config]()
45+
46+
3. Logical Combinators
47+
48+
- Conjunction:
49+
cond := And(condition1, condition2)
50+
51+
- Disjunction:
52+
cond := Or(condition1, condition2)
53+
54+
- Negation:
55+
cond := Not(condition)
56+
57+
- Universal negation:
58+
cond := None(condition1, condition2)
59+
60+
4. Custom Conditions
61+
62+
- Functional condition:
63+
cond := OnFunc(func(ctx gs.CondContext) (bool, error) {
64+
return time.Now().Hour() > 9, nil
65+
})
66+
67+
- Expression condition (Pending implementation):
68+
cond := OnExpression("beans('redis').size() > 0")
69+
*/
1770
package gs_cond
1871

1972
import (

gs/internal/gs_conf/conf.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
Package gs_conf provides hierarchical configuration management
19+
with multi-source support for Go-Spring framework.
20+
21+
Key Features:
22+
23+
1. Command-line argument parsing
24+
- Supports `-D key[=value]` format arguments
25+
- Customizable prefix via `GS_ARGS_PREFIX` environment variable
26+
- Example: `./app -D server.port=8080 -D debug`
27+
28+
2. Environment variable handling
29+
- Automatic loading of `GS_` prefixed variables
30+
- Conversion rules: `GS_DB_HOST=127.0.0.1` → `db.host=127.0.0.1`
31+
- Direct mapping of non-prefixed environment variables
32+
33+
3. Configuration file management
34+
- Supports properties/yaml/toml/json formats
35+
- Local configurations: ./conf/app.{properties|yaml|toml|json}
36+
- Remote configurations: ./conf/remote/app.{properties|yaml|toml|json}
37+
- Profile-based configurations (e.g., app-dev.properties)
38+
39+
4. Layered configuration hierarchy
40+
- Priority order: System config → File config → Env variables → CLI arguments
41+
- Provides AppConfig (application context) and BootConfig (boot context)
42+
- High-priority configurations override lower ones
43+
*/
1744
package gs_conf
1845

1946
import (

gs/internal/gs_dync/dync.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,50 @@
1414
* limitations under the License.
1515
*/
1616

17+
/*
18+
Package gs_dync provides dynamic configuration binding and
19+
refresh capabilities for Go applications.
20+
21+
Features:
22+
- Thread-safe atomic.Value based storage with automatic type conversion
23+
- Property change listeners with channel-based notifications
24+
- Hierarchical configuration key resolution (supports nested structs and map keys)
25+
- Live configuration updates with granular change detection
26+
- JSON serialization support for configuration values
27+
28+
Examples:
29+
30+
Basic value binding:
31+
32+
var v Value[int]
33+
_ = v.onRefresh(conf.Map(map[string]any{"key": 42}), conf.BindParam{Key: "key"})
34+
fmt.Print(v.Value()) // Output: 42
35+
36+
Struct binding with nested configuration:
37+
38+
type Config struct {
39+
Server struct {
40+
Port Value[int] `value:"${port}"`
41+
} `value:"${server}"`
42+
}
43+
44+
var cfg Config
45+
_ = p.RefreshField(reflect.ValueOf(&cfg), conf.BindParam{Key: "config"})
46+
47+
JSON serialization:
48+
49+
b, _ := json.Marshal(map[string]any{"key": &v})
50+
fmt.Print(string(b)) // Output: {"key":42}
51+
52+
Change notification:
53+
54+
listener := v.NewListener()
55+
go func() {
56+
<-listener.C
57+
fmt.Print("value changed!")
58+
}()
59+
_ = v.onRefresh(conf.Map(map[string]any{"key": 100}), conf.BindParam{Key: "key"})
60+
*/
1761
package gs_dync
1862

1963
import (

0 commit comments

Comments
 (0)