Skip to content

Commit 12c5f16

Browse files
committed
chore(all): create and use ServiceContextWithConfig
1 parent fb537e9 commit 12c5f16

File tree

42 files changed

+156
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+156
-158
lines changed

benchmarks/event/cmd/handler/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
Name: "log_level",
2424
Default: "INFO",
2525
EnvVars: []string{"LOG_LEVEL"},
26-
ConfigPaths: []cli.FlagConfigPath{{Path: []string{"logger", "level"}}},
26+
ConfigPaths: [][]string{{"logger", "level"}},
2727
Usage: "Set the log level, one of TRACE, DEBUG, INFO, WARN, ERROR",
2828
},
2929
},

benchmarks/event/cmd/handler/wire.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
type wireRunResult struct{}
2121

2222
func wireRun(
23-
serviceContext *cli.ServiceContext,
23+
serviceContext *cli.ServiceContextWithConfig,
2424
components *types.Components,
2525
logger log.Logger,
2626
eventHandler event.Type,

benchmarks/event/cmd/handler/wire_gen.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/event/cmd/request/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,47 +27,47 @@ func flags() []*cli.Flag {
2727
flags = append(flags, cli.NewFlag(
2828
"connections",
2929
defaultConnections,
30-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "connections"}}),
30+
cli.FlagConfigPaths([]string{configSection, "connections"}),
3131
cli.FlagUsage("Connections to keep open"),
3232
cli.FlagEnvVars("CONNECTIONS"),
3333
))
3434

3535
flags = append(flags, cli.NewFlag(
3636
"duration",
3737
defaultDuration,
38-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "duration"}}),
38+
cli.FlagConfigPaths([]string{configSection, "duration"}),
3939
cli.FlagUsage("Duration in seconds"),
4040
cli.FlagEnvVars("DURATION"),
4141
))
4242

4343
flags = append(flags, cli.NewFlag(
4444
"timeout",
4545
defaultTimeout,
46-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "timeout"}}),
46+
cli.FlagConfigPaths([]string{configSection, "timeout"}),
4747
cli.FlagUsage("Timeout in seconds"),
4848
cli.FlagEnvVars("TIMEOUT"),
4949
))
5050

5151
flags = append(flags, cli.NewFlag(
5252
"threads",
5353
defaultThreads,
54-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "threads"}}),
54+
cli.FlagConfigPaths([]string{configSection, "threads"}),
5555
cli.FlagUsage("Number of threads to use = runtime.GOMAXPROCS()"),
5656
cli.FlagEnvVars("THREADS"),
5757
))
5858

5959
flags = append(flags, cli.NewFlag(
6060
"package_size",
6161
defaultPackageSize,
62-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "packageSize"}}),
62+
cli.FlagConfigPaths([]string{configSection, "packageSize"}),
6363
cli.FlagUsage("Per request package size"),
6464
cli.FlagEnvVars("PACKAGE_SIZE"),
6565
))
6666

6767
flags = append(flags, cli.NewFlag(
6868
"content_type",
6969
defaultContentType,
70-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "contentType"}}),
70+
cli.FlagConfigPaths([]string{configSection, "contentType"}),
7171
cli.FlagUsage("Content-Type (application/x-protobuf, application/x-protobuf+json)"),
7272
cli.FlagEnvVars("CONTENT_TYPE"),
7373
))

benchmarks/event/cmd/request/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func connection(
9595
//
9696
//nolint:funlen
9797
func bench(
98-
svcCtx *cli.ServiceContext,
98+
svcCtx *cli.ServiceContextWithConfig,
9999
logger log.Logger,
100100
eventHandler event.Type,
101101
) error {
@@ -107,7 +107,7 @@ func bench(
107107
PackageSize: defaultPackageSize,
108108
}
109109

110-
if err := config.Parse(nil, event.DefaultConfigSection, svcCtx.Config, &cfg); err != nil && !errors.Is(err, config.ErrNoSuchKey) {
110+
if err := config.Parse(nil, event.DefaultConfigSection, svcCtx.Config(), &cfg); err != nil && !errors.Is(err, config.ErrNoSuchKey) {
111111
return err
112112
}
113113

@@ -225,7 +225,7 @@ func main() {
225225
Name: "log_level",
226226
Default: "INFO",
227227
EnvVars: []string{"LOG_LEVEL"},
228-
ConfigPaths: []cli.FlagConfigPath{{Path: []string{"logger", "level"}}},
228+
ConfigPaths: [][]string{{configSection, "logLevel"}},
229229
Usage: "Set the log level, one of TRACE, DEBUG, INFO, WARN, ERROR",
230230
},
231231
},

benchmarks/event/cmd/request/wire.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ type wireRunResult struct{}
2222

2323
// wireRunCallback is the actual code that runs the business logic.
2424
type wireRunCallback func(
25-
svcCtx *cli.ServiceContext,
25+
svcCtx *cli.ServiceContextWithConfig,
2626
logger log.Logger,
2727
eventHandler event.Type,
2828
) error
2929

3030
func wireRun(
31-
serviceContext *cli.ServiceContext,
31+
serviceContext *cli.ServiceContextWithConfig,
3232
components *types.Components,
3333
logger log.Logger,
3434
event event.Type,

benchmarks/event/cmd/request/wire_gen.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/rps/cmd/orb-rps-client/config.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
configSection = "bench_client"
10+
configSection = "benchClient"
1111

1212
defaultBypassRegistry = 1
1313
defaultConnections = 256
@@ -30,75 +30,71 @@ func flags() []*cli.Flag {
3030
flags = append(flags, cli.NewFlag(
3131
"bypass_registry",
3232
defaultBypassRegistry,
33-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "bypassRegistry"}, IsGlobal: true}),
33+
cli.FlagConfigPaths([]string{configSection, "bypassRegistry"}),
3434
cli.FlagUsage("Bypasses the registry by caching it, set to 0 to disable"),
3535
cli.FlagEnvVars("BYPASS_REGISTRY"),
3636
))
3737

3838
flags = append(flags, cli.NewFlag(
3939
"pool_size",
4040
defaultPoolSize,
41-
cli.FlagConfigPaths(
42-
cli.FlagConfigPath{Path: []string{"client", "poolSize"}},
43-
),
41+
cli.FlagConfigPaths([]string{"client", "poolSize"}),
4442
cli.FlagUsage("Number of connections to keep open"),
4543
cli.FlagEnvVars("POOL_SIZE"),
4644
))
4745

4846
flags = append(flags, cli.NewFlag(
4947
"connections",
5048
defaultConnections,
51-
cli.FlagConfigPaths(
52-
cli.FlagConfigPath{Path: []string{configSection, "connections"}, IsGlobal: true},
53-
),
49+
cli.FlagConfigPaths([]string{configSection, "connections"}),
5450
cli.FlagUsage("Connections to keep open"),
5551
cli.FlagEnvVars("CONNECTIONS"),
5652
))
5753

5854
flags = append(flags, cli.NewFlag(
5955
"duration",
6056
defaultDuration,
61-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "duration"}, IsGlobal: true}),
57+
cli.FlagConfigPaths([]string{configSection, "duration"}),
6258
cli.FlagUsage("Duration in seconds"),
6359
cli.FlagEnvVars("DURATION"),
6460
))
6561

6662
flags = append(flags, cli.NewFlag(
6763
"timeout",
6864
defaultTimeout,
69-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "timeout"}, IsGlobal: true}),
65+
cli.FlagConfigPaths([]string{configSection, "timeout"}),
7066
cli.FlagUsage("Timeout in seconds"),
7167
cli.FlagEnvVars("TIMEOUT"),
7268
))
7369

7470
flags = append(flags, cli.NewFlag(
7571
"threads",
7672
defaultThreads,
77-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "threads"}, IsGlobal: true}),
73+
cli.FlagConfigPaths([]string{configSection, "threads"}),
7874
cli.FlagUsage("Number of threads to use = runtime.GOMAXPROCS()"),
7975
cli.FlagEnvVars("THREADS"),
8076
))
8177

8278
flags = append(flags, cli.NewFlag(
8379
"transport",
8480
defaultTransport,
85-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "transport"}, IsGlobal: true}),
81+
cli.FlagConfigPaths([]string{configSection, "transport"}),
8682
cli.FlagUsage("Transport to use (grpc, drpc, http, uvm.)"),
8783
cli.FlagEnvVars("TRANSPORT"),
8884
))
8985

9086
flags = append(flags, cli.NewFlag(
9187
"package_size",
9288
defaultPackageSize,
93-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "packageSize"}, IsGlobal: true}),
89+
cli.FlagConfigPaths([]string{configSection, "packageSize"}),
9490
cli.FlagUsage("Per request package size"),
9591
cli.FlagEnvVars("PACKAGE_SIZE"),
9692
))
9793

9894
flags = append(flags, cli.NewFlag(
9995
"content_type",
10096
defaultContentType,
101-
cli.FlagConfigPaths(cli.FlagConfigPath{Path: []string{configSection, "contentType"}, IsGlobal: true}),
97+
cli.FlagConfigPaths([]string{configSection, "contentType"}),
10298
cli.FlagUsage("Content-Type (application/x-protobuf, application/x-protobuf+json)"),
10399
cli.FlagEnvVars("CONTENT_TYPE"),
104100
))

benchmarks/rps/cmd/orb-rps-client/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
_ "github.com/go-orb/plugins/client/orb"
2525
_ "github.com/go-orb/plugins/codecs/goccyjson"
2626
_ "github.com/go-orb/plugins/codecs/proto"
27+
_ "github.com/go-orb/plugins/codecs/yaml"
2728
_ "github.com/go-orb/plugins/config/source/file"
2829
_ "github.com/go-orb/plugins/log/slog"
2930
_ "github.com/go-orb/plugins/registry/consul"
@@ -214,14 +215,14 @@ func main() {
214215
Name: "registry",
215216
Default: registry.DefaultRegistry,
216217
EnvVars: []string{"REGISTRY"},
217-
ConfigPaths: []cli.FlagConfigPath{{Path: []string{"registry", "plugin"}}},
218+
ConfigPaths: [][]string{{"registry", "plugin"}},
218219
Usage: "Set the registry plugin, one of mdns, consul, memory",
219220
},
220221
{
221222
Name: "log_level",
222223
Default: "INFO",
223224
EnvVars: []string{"LOG_LEVEL"},
224-
ConfigPaths: []cli.FlagConfigPath{{Path: []string{"logger", "level"}}},
225+
ConfigPaths: [][]string{{"logger", "level"}},
225226
Usage: "Set the log level, one of TRACE, DEBUG, INFO, WARN, ERROR",
226227
},
227228
},

benchmarks/rps/cmd/orb-rps-client/wire.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type wireRunCallback func(
3232
type wireRunResult struct{}
3333

3434
func wireRun(
35-
serviceContext *cli.ServiceContext,
35+
serviceContext *cli.ServiceContextWithConfig,
3636
components *types.Components,
3737
cfg *clientConfig,
3838
logger log.Logger,
@@ -68,7 +68,7 @@ func wireRun(
6868
return wireRunResult{}, runErr
6969
}
7070

71-
func provideClientConfig(svcCtx *cli.ServiceContext) (*clientConfig, error) {
71+
func provideClientConfig(svcCtx *cli.ServiceContextWithConfig) (*clientConfig, error) {
7272
cfg := &clientConfig{
7373
BypassRegistry: defaultBypassRegistry,
7474
PoolSize: defaultPoolSize,
@@ -81,7 +81,7 @@ func provideClientConfig(svcCtx *cli.ServiceContext) (*clientConfig, error) {
8181
ContentType: defaultContentType,
8282
}
8383

84-
if err := config.Parse(nil, configSection, svcCtx.Config, &cfg); err != nil && !errors.Is(err, config.ErrNoSuchKey) {
84+
if err := config.Parse(nil, configSection, svcCtx.Config(), &cfg); err != nil && !errors.Is(err, config.ErrNoSuchKey) {
8585
return nil, err
8686
}
8787

0 commit comments

Comments
 (0)