Skip to content

Commit f97bef9

Browse files
committed
docs: add examples and template links
1 parent db7c7f0 commit f97bef9

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
88

99
[**English**](./README.md)
10-
[**简体中文**](./README_CN.md)
10+
[**简体中文**](./README_CN.md) |
11+
[**Examples**](./example_test.go)
12+
[**Template**](https://github.com/go-kod/kod-mono)
1113

1214
</div>
1315

example_test.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func Example_helloWorld() {
18-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
18+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
1919
fmt.Println("Hello, World!")
2020
return nil
2121
})
@@ -26,8 +26,8 @@ func Example_helloWorld() {
2626
}
2727

2828
func Example_callComponent() {
29-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
30-
t.HelloWorld.Get().SayHello(ctx)
29+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
30+
app.HelloWorld.Get().SayHello(ctx)
3131
return nil
3232
})
3333
// Output:
@@ -40,8 +40,8 @@ func Example_mockComponent() {
4040
mock := helloworld.NewMockHelloWorld(gomock.NewController(nil))
4141
mock.EXPECT().SayHello(gomock.Any()).Return()
4242

43-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
44-
t.HelloWorld.Get().SayHello(ctx)
43+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
44+
app.HelloWorld.Get().SayHello(ctx)
4545
fmt.Println("Nothing printed from mock")
4646
return nil
4747
}, kod.WithFakes(kod.Fake[helloworld.HelloWorld](mock)))
@@ -50,9 +50,9 @@ func Example_mockComponent() {
5050
}
5151

5252
func Example_config() {
53-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
54-
fmt.Println(t.Config().Name)
55-
t.HelloWorld.Get().SayHello(ctx)
53+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
54+
fmt.Println(app.Config().Name)
55+
app.HelloWorld.Get().SayHello(ctx)
5656
return nil
5757
}, kod.WithConfigFile("./examples/helloworld/config.toml"))
5858
// Output:
@@ -65,11 +65,11 @@ func Example_config() {
6565
func Example_log() {
6666
wrapper, observer := kod.NewLogObserver()
6767

68-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
69-
t.L(ctx).Debug("Hello, World!")
70-
t.L(ctx).Info("Hello, World!")
71-
t.L(ctx).Warn("Hello, World!")
72-
t.L(ctx).Error("Hello, World!")
68+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
69+
app.L(ctx).Debug("Hello, World!")
70+
app.L(ctx).Info("Hello, World!")
71+
app.L(ctx).Warn("Hello, World!")
72+
app.L(ctx).Error("Hello, World!")
7373
return nil
7474
}, kod.WithLogWrapper(wrapper))
7575

@@ -95,8 +95,8 @@ func Example_interceptor() {
9595
return err
9696
})
9797

98-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
99-
t.HelloWorld.Get().SayHello(ctx)
98+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
99+
app.HelloWorld.Get().SayHello(ctx)
100100
return nil
101101
}, kod.WithInterceptors(interceptor))
102102
// Output:
@@ -108,8 +108,8 @@ func Example_interceptor() {
108108
}
109109

110110
func Example_builtinInterceptor() {
111-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
112-
t.HelloWorld.Get().SayHello(ctx)
111+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
112+
app.HelloWorld.Get().SayHello(ctx)
113113
return nil
114114
}, kod.WithInterceptors(krecovery.Interceptor(), ktrace.Interceptor(), kmetric.Interceptor()))
115115
// Output:
@@ -119,8 +119,8 @@ func Example_builtinInterceptor() {
119119
}
120120

121121
func Example_test() {
122-
kod.RunTest(&testing.T{}, func(ctx context.Context, t *helloworld.App) {
123-
t.HelloWorld.Get().SayHello(ctx)
122+
kod.RunTest(&testing.T{}, func(ctx context.Context, app *helloworld.App) {
123+
app.HelloWorld.Get().SayHello(ctx)
124124
})
125125
// Output:
126126
// helloWorld init
@@ -132,18 +132,18 @@ func Example_testWithMockComponent() {
132132
mock := helloworld.NewMockHelloWorld(gomock.NewController(nil))
133133
mock.EXPECT().SayHello(gomock.Any()).Return()
134134

135-
kod.RunTest(&testing.T{}, func(ctx context.Context, t *helloworld.App) {
136-
t.HelloWorld.Get().SayHello(ctx)
135+
kod.RunTest(&testing.T{}, func(ctx context.Context, app *helloworld.App) {
136+
app.HelloWorld.Get().SayHello(ctx)
137137
fmt.Println("Nothing printed from mock")
138138
}, kod.WithFakes(kod.Fake[helloworld.HelloWorld](mock)))
139139
// Output:
140140
// Nothing printed from mock
141141
}
142142

143143
func Example_lazyInit() {
144-
kod.Run(context.Background(), func(ctx context.Context, t *helloworld.App) error {
145-
t.HelloBob.Get().SayHello(ctx)
146-
t.HelloWorld.Get().SayHello(ctx)
144+
kod.Run(context.Background(), func(ctx context.Context, app *helloworld.App) error {
145+
app.HelloBob.Get().SayHello(ctx)
146+
app.HelloWorld.Get().SayHello(ctx)
147147
return nil
148148
})
149149
// Output:

0 commit comments

Comments
 (0)