@@ -4,95 +4,6 @@ A way to structure your application modules.
44
55<img width =" 573 " height =" 435 " alt =" Screenshot 2025-09-26 at 10 14 57 " src =" https://github.com/user-attachments/assets/3e67e0f7-dd48-4ca0-98e5-80d216e86749 " />
66
7- ^ Output of internal [ tool] ( https://github.com/roboslone/go-framework/blob/main/.tools/main.go#L13 ) built on ` go-framework ` .
8- Linting and testing are done in parallel.
9-
10- ## Example
11-
12- ``` go
13- // State describes your application, both configuration and runtime.
14- // In this example state configures `Interval` for "incrementer" and "printer" modules,
15- // and also stores `Counter`, which is modified by "incrementer" and read by "printer".
16- type State {
17- // configuration
18- Interval time.Duration
19-
20- // runtime
21- Counter int
22- }
23-
24- // CounterIncrementer is a simple module, that increments given `Counter` each `Interval`.
25- type CounterIncrementer struct {}
26-
27- func (*CounterIncrementer ) Start (ctx context .Context , s *State ) error {
28- go func () {
29- timedLoop (ctx, s.Interval , func () { s.Counter ++ })
30- }()
31- return nil
32- }
33-
34- // CounterPrinter is a simple module, that prints given `Counter` each `Interval`.
35- // It depends on CounterIncrementer.
36- type CounterPrinter struct {}
37-
38- func (*CounterPrinter ) Start (ctx context .Context , s *State ) error {
39- go func () {
40- timedLoop (ctx, s.Interval , func () { log.Println (s.Counter ) })
41- }()
42- return nil
43- }
44-
45- func (*CounterPrinter ) Dependencies (_ context .Context ) []string {
46- return []string {
47- " incrementer" ,
48- }
49- }
50-
51- func timedLoop (ctx context.Context , d time.Duration , fn func ()) {
52- ticker := time.NewTicker (d)
53- defer ticker.Stop ()
54-
55- for {
56- select {
57- case <- ticker.C :
58- fn ()
59- case <- ctx.Done ():
60- return
61- }
62- }
63- }
64-
65- // App contains all available modules and their dependencies.
66- var App = framework.NewApplication [State](
67- " counter" ,
68- framework.Modules {
69- " incrementer" : &CounterIncrementer{},
70- " printer" : &CounterPrinter{},
71- },
72- )
73-
74- // Prepares and starts both `incrementer` and `printer`.
75- App.Run (context.Background (), &State{}, " printer" )
76-
77- // To ensure all your application modules are valid (satisfy at least one module interface):
78- func TestApp (t *testing .T ) {
79- if err := App.Check (); err != nil {
80- t.Error (err)
81- }
82- }
83- ```
84-
85- ## Module interfaces
86- Available interfaces can be found in ` module.go ` :
87-
88- ``` go
89- Dependent
90- Preparable[State any]
91- Startable[State any]
92- Awaitable[State any]
93- Cleanable[State any]
94- ```
95-
967## Command line tool
978There's a command line tool for running simple command modules (` framework.CommandModule ` ).
989
@@ -137,3 +48,14 @@ fexec --help
13748# pre-commit
13849# depends on lint, test
13950```
51+
52+ ## Module interfaces
53+ Available interfaces can be found in ` module.go ` :
54+
55+ ``` go
56+ Dependent
57+ Preparable[State any]
58+ Startable[State any]
59+ Awaitable[State any]
60+ Cleanable[State any]
61+ ```
0 commit comments