Skip to content

Commit

Permalink
linter;
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kamieth committed Oct 1, 2024
1 parent 393e5aa commit 847794d
Show file tree
Hide file tree
Showing 40 changed files with 161 additions and 138 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- misspell # Finds commonly misspelled English words in comments.
- nestif # Reports deeply nested if statements.
- nlreturn # Nlreturn checks for a new line before return and branch statements to increase code clarity.
- revive
- staticcheck # It's a set of rules from staticcheck.
- tenv # Tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17.
- typecheck
Expand Down Expand Up @@ -76,6 +77,10 @@ linters-settings:
nestif:
min-complexity: 4

revive:
rules:
- name: use-any

issues:
exclude-rules:
- path: _test\.go
Expand Down
23 changes: 14 additions & 9 deletions docs/docs/reference/package-fixtures.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ fixtures:
```
* Make sure to use a custom build tag named `fixtures`

* Define your fixtures in code while using one of the built in `FixtureWriter`s and defining a slice of `[]fixtures.FixtureSet{}` or use `fixtures.FixtureSetFactory` or `fixtures.FixtureSetsFactory` depending on your use-case.
For more details check the `/examples/gosoline-fixture-loading` Directory or read the short example below.

* The `fixtures.FixtureSet` interface allows you to define any custom implementation for writing fixture sets to their destination and take control of purging prior writing too.
You can however use the `fixures.simpleFixtureSet` via the `fixtures.NewSimpleFixtureSet` factory func to use a simple yet effective and prebuilt solution.
This is the simpleFixtureSet struct definition:
* Define your fixtures in code while using one of the built in `FixtureWriter`s and defining a slice of
`[]fixtures.FixtureSet{}` or use `fixtures.FixtureSetFactory` or `fixtures.FixtureSetsFactory` depending on your use-case.
For more details check the `/examples/fixtures` Directory or read the short example below.

* The `fixtures.FixtureSet` interface allows you to define any custom implementation for writing fixture sets to their
destination and take control of purging prior writing too. You can however use the `fixures.simpleFixtureSet` via the
`fixtures.NewSimpleFixtureSet` factory func to use a simple yet effective and prebuilt solution. This is the simpleFixtureSet
struct definition:
```
type simpleFixtureSet[T any] struct {
Enabled bool
Expand All @@ -28,7 +30,9 @@ type simpleFixtureSet[T any] struct {
Fixtures NamedFixtures[T]
}
```
You can easily define multiple fixtures for different destinations in one file, enable/disable them or even enable/disable purging for each `fixtures.FixtureSet` via the `fixtures.WithEnabled` and `fixtures.WithPurge` `fixtures.FixtureSetOption` for the `fixtures.NewSimpleFixtureSet` func.
You can easily define multiple fixtures for different destinations in one file, enable/disable them or even enable/disable
purging for each `fixtures.FixtureSet` via the `fixtures.WithEnabled` and `fixtures.WithPurge` `fixtures.FixtureSetOption`
for the `fixtures.NewSimpleFixtureSet` func.

* Currently there are 7 different FixtureWriter implementations for loading fixtures:
<table>
Expand Down Expand Up @@ -80,13 +84,14 @@ You can easily define multiple fixtures for different destinations in one file,
</table>

## Quick Usage
* During the creation of your Application make sure to pass the `WithFixtureSetsFactory` option and provide a fixture sets factory as an argument of type `fixtures.WithFixtureSetsFactory`
* During the creation of your Application make sure to pass the `WithFixtureSetsFactory` option and provide the group name
and a fixture sets factory as arguments of type `fixtures.WithFixtureSetsFactory`. The `default` group is enabled by default.

[embedmd]:# (../../examples/fixtures/simple/main.go /func main/ /}/)
```go
func main() {
app := application.Default(
application.WithFixtureSetFactory(fixtureSetsFactory),
application.WithFixtureSetFactory("default", fixtureSetsFactory),
)

app.Run()
Expand Down
8 changes: 4 additions & 4 deletions pkg/application/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func WithConfigFileFlag(app *App) {
})
}

func WithConfigMap(configMap map[string]interface{}, mergeOptions ...cfg.MergeOption) Option {
func WithConfigMap(configMap map[string]any, mergeOptions ...cfg.MergeOption) Option {
return func(app *App) {
app.addConfigOption(func(config cfg.GosoConf) error {
return config.Option(cfg.WithConfigMap(configMap, mergeOptions...))
Expand All @@ -126,7 +126,7 @@ func WithConfigSanitizers(sanitizers ...cfg.Sanitizer) Option {
}
}

func WithConfigSetting(key string, settings interface{}) Option {
func WithConfigSetting(key string, settings any) Option {
return func(app *App) {
app.addConfigOption(func(config cfg.GosoConf) error {
return config.Option(cfg.WithConfigSetting(key, settings))
Expand Down Expand Up @@ -188,7 +188,7 @@ func WithLoggerGroupTag(app *App) {
return errors.New("can not get application group from config to set it on logger")
}

return logger.Option(log.WithFields(map[string]interface{}{
return logger.Option(log.WithFields(map[string]any{
"group": config.GetString("app_group"),
}))
})
Expand All @@ -200,7 +200,7 @@ func WithLoggerApplicationTag(app *App) {
return errors.New("can not get application name from config to set it on logger")
}

return logger.Option(log.WithFields(map[string]interface{}{
return logger.Option(log.WithFields(map[string]any{
"application": config.GetString("app_name"),
}))
})
Expand Down
10 changes: 9 additions & 1 deletion pkg/cloud/aws/awsv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func NewLogger(base log.Logger) *Logger {
}
}

func (l Logger) Logf(classification logging.Classification, format string, v ...interface{}) {
func (l Logger) Logf(classification logging.Classification, format string, v ...any) {
switch classification {
case logging.Warn:
l.base.Warn(format, v...)
Expand All @@ -178,3 +178,11 @@ func (l Logger) WithContext(ctx context.Context) logging.Logger {
func GetClientConfigKey(service string, name string) string {
return fmt.Sprintf("cloud.aws.%s.clients.%s", service, name)
}

func NilIfEmpty[T comparable](val T) *T {
if *new(T) == val {
return nil
}

return &val
}
2 changes: 1 addition & 1 deletion pkg/cloud/aws/cloudwatch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := cloudwatch.NewFromConfig(awsConfig, func(options *cloudwatch.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "cloudwatch", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/dynamodb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := dynamodb.NewFromConfig(awsConfig, func(options *dynamodb.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "dynamodb", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/ec2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := ec2.NewFromConfig(awsConfig, func(options *ec2.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "ec2", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := ecs.NewFromConfig(awsConfig, func(options *ecs.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "ecs", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/kinesis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := kinesis.NewFromConfig(awsConfig, func(options *kinesis.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "kinesis", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/rds/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := rds.NewFromConfig(awsConfig, func(options *rds.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "rds", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/resourcegroupstaggingapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := resourcegroupstaggingapi.NewFromConfig(awsConfig, func(options *resourcegroupstaggingapi.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "resourcegroupstaggingapi", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := s3.NewFromConfig(awsConfig, func(o *s3.Options) {
o.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
o.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
o.UsePathStyle = clientCfg.Settings.UsePathStyle
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/secretsmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := secretsmanager.NewFromConfig(awsConfig, func(options *secretsmanager.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "secretsmanager", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/servicediscovery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := servicediscovery.NewFromConfig(awsConfig, func(options *servicediscovery.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "servicediscovery", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/sns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := sns.NewFromConfig(awsConfig, func(options *sns.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "sns", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/sqs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := sqs.NewFromConfig(awsConfig, func(options *sqs.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "sqs", name, clientCfg.Settings.ClientSettings)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/ssm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewClient(ctx context.Context, config cfg.Config, logger log.Logger, name s
}

client := ssm.NewFromConfig(awsConfig, func(options *ssm.Options) {
options.BaseEndpoint = aws.String(clientCfg.Settings.Endpoint)
options.BaseEndpoint = gosoAws.NilIfEmpty(clientCfg.Settings.Endpoint)
})

gosoAws.LogNewClientCreated(ctx, logger, "ssm", name, clientCfg.Settings.ClientSettings)
Expand Down
Loading

0 comments on commit 847794d

Please sign in to comment.