Skip to content

Commit

Permalink
add doc for run about func() []any (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored May 5, 2024
1 parent 2d466dd commit eb2000d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
6 changes: 1 addition & 5 deletions gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ func TestOptions(t *testing.T) {
{
description: "with options",
opts: []gcp.Option{
gcp.WithOptions(func() []gcp.Option {
return []gcp.Option{
gcp.WithProject("project"),
}
}),
gcp.WithProject("project"),
},
assertion: func(t *testing.T, opts []any) {
t.Helper()
Expand Down
11 changes: 0 additions & 11 deletions gcp/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ func WithMetric(opts ...otlpmetricgrpc.Option) Option {
}
}

// WithOptions provides the function which returns multiple Option(s).
// It's useful while the Option needs to read configuration from config,
// since it defers the creation of Option(s) until the config is loaded.
func WithOptions(f func() []Option) Option {
return func(options *options) {
for _, opt := range f() {
opt(options)
}
}
}

type (
// Option configures the GCP runtime with specific options.
Option func(*options)
Expand Down
4 changes: 4 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
// - log.Option
// - run.Option
// - func(context.Context) error
//
// By default, above args are statics which could not change according to the configuration.
// If the args need to by dynamic, it should be wrapped in func() []any,
// which returns args according to the configuration.
func Run(args ...any) error {
// Setup configuration first so others can use it.
var configOpts []config.Option
Expand Down

0 comments on commit eb2000d

Please sign in to comment.