File tree Expand file tree Collapse file tree 6 files changed +173
-5
lines changed Expand file tree Collapse file tree 6 files changed +173
-5
lines changed Original file line number Diff line number Diff line change 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+ */
2247package gstest
2348
2449import (
Original file line number Diff line number Diff line change 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+ */
1727package gs_arg
1828
1929import (
Original file line number Diff line number Diff line change 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+ */
1726package gs_bean
1827
1928import (
Original file line number Diff line number Diff line change 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+ */
1770package gs_cond
1871
1972import (
Original file line number Diff line number Diff line change 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+ */
1744package gs_conf
1845
1946import (
Original file line number Diff line number Diff line change 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+ */
1761package gs_dync
1862
1963import (
You can’t perform that action at this time.
0 commit comments