Skip to content

Commit 37613cb

Browse files
committed
feat(main): Updated template bootstrap
1 parent ace45a4 commit 37613cb

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23
44

55
require (
66
github.com/ankorstore/yokai/config v1.5.0
7+
github.com/ankorstore/yokai/fxconfig v1.3.0
78
github.com/ankorstore/yokai/fxcore v1.9.0
89
github.com/ankorstore/yokai/fxgrpcserver v1.3.0
910
github.com/ankorstore/yokai/grpcserver v1.2.0
@@ -17,7 +18,6 @@ require (
1718
)
1819

1920
require (
20-
github.com/ankorstore/yokai/fxconfig v1.3.0 // indirect
2121
github.com/ankorstore/yokai/fxgenerate v1.2.0 // indirect
2222
github.com/ankorstore/yokai/fxhealthcheck v1.1.0 // indirect
2323
github.com/ankorstore/yokai/fxlog v1.1.0 // indirect

internal/bootstrap.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8+
"github.com/ankorstore/yokai/fxconfig"
89
"github.com/ankorstore/yokai/fxcore"
910
"github.com/ankorstore/yokai/fxgrpcserver"
1011
"go.uber.org/fx"
@@ -34,7 +35,11 @@ func Run(ctx context.Context) {
3435
func RunTest(tb testing.TB, options ...fx.Option) {
3536
tb.Helper()
3637

37-
tb.Setenv("APP_CONFIG_PATH", fmt.Sprintf("%s/configs", RootDir))
38-
39-
Bootstrapper.RunTestApp(tb, fx.Options(options...))
38+
Bootstrapper.RunTestApp(
39+
tb,
40+
// config lookup
41+
fxconfig.AsConfigPath(fmt.Sprintf("%s/configs/", RootDir)),
42+
// test options
43+
fx.Options(options...),
44+
)
4045
}

internal/service/example.go

+23-16
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,37 @@ func (s *ExampleService) ExampleStreaming(stream proto.ExampleService_ExampleStr
4747
logger := log.CtxLogger(ctx)
4848

4949
for {
50-
req, err := stream.Recv()
50+
select {
51+
case <-ctx.Done():
52+
logger.Info().Msg("rpc context cancelled")
5153

52-
if errors.Is(err, io.EOF) {
53-
logger.Info().Msg("end of rpc")
54+
return ctx.Err()
55+
default:
56+
req, err := stream.Recv()
5457

55-
return nil
56-
}
58+
if errors.Is(err, io.EOF) {
59+
logger.Info().Msg("end of rpc")
5760

58-
if err != nil {
59-
logger.Error().Err(err).Msgf("error while receiving: %v", err)
60-
}
61+
return nil
62+
}
63+
64+
if err != nil {
65+
logger.Error().Err(err).Msgf("error while receiving: %v", err)
66+
}
6167

62-
logger.Info().Msgf("received: %s", req.Text)
68+
logger.Info().Msgf("received: %s", req.Text)
6369

64-
span.AddEvent(fmt.Sprintf("received: %s", req.Text))
70+
span.AddEvent(fmt.Sprintf("received: %s", req.Text))
6571

66-
err = stream.Send(&proto.ExampleResponse{
67-
Text: fmt.Sprintf("response from %s: you sent %s", s.config.AppName(), req.Text),
68-
})
72+
err = stream.Send(&proto.ExampleResponse{
73+
Text: fmt.Sprintf("response from %s: you sent %s", s.config.AppName(), req.Text),
74+
})
6975

70-
if err != nil {
71-
logger.Error().Err(err).Msgf("error while sending: %v", err)
76+
if err != nil {
77+
logger.Error().Err(err).Msgf("error while sending: %v", err)
7278

73-
return err
79+
return err
80+
}
7481
}
7582
}
7683
}

0 commit comments

Comments
 (0)