internal/config: reimplement overrideXXX functions with generics
Also, comment out unparam because it doesn't work on generic
code yet.
Change-Id: I821e29e9011781d851b9b468dae56f47695d7450
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/389655
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/all.bash b/all.bash
index 1702001..7be8835 100755
--- a/all.bash
+++ b/all.bash
@@ -135,8 +135,10 @@
# check_unparam runs unparam on source files.
check_unparam() {
- ensure_go_binary mvdan.cc/unparam
- runcmd unparam ./...
+ echo "unparam disabled until go 1.18"
+# TODO: uncomment when updated to go 1.18
+ # ensure_go_binary mvdan.cc/unparam
+ # runcmd unparam ./...
}
# check_vet runs go vet on source files.
diff --git a/internal/config/config.go b/internal/config/config.go
index bda15bf..42d264f 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -549,33 +549,20 @@
log.Errorf(ctx, "processOverrides: yaml.Unmarshal: %v", err)
return
}
- overrideString(ctx, "DBHost", &cfg.DBHost, ov.DBHost)
- overrideString(ctx, "DBSecondaryHost", &cfg.DBSecondaryHost, ov.DBSecondaryHost)
- overrideString(ctx, "DBName", &cfg.DBName, ov.DBName)
- overrideInt(ctx, "Quota.QPS", &cfg.Quota.QPS, ov.Quota.QPS)
- overrideInt(ctx, "Quota.Burst", &cfg.Quota.Burst, ov.Quota.Burst)
- overrideInt(ctx, "Quota.MaxEntries", &cfg.Quota.MaxEntries, ov.Quota.MaxEntries)
- overrideBool(ctx, "Quota.RecordOnly", &cfg.Quota.RecordOnly, ov.Quota.RecordOnly)
+ override(ctx, "DBHost", &cfg.DBHost, ov.DBHost)
+ override(ctx, "DBSecondaryHost", &cfg.DBSecondaryHost, ov.DBSecondaryHost)
+ override(ctx, "DBName", &cfg.DBName, ov.DBName)
+ override(ctx, "Quota.QPS", &cfg.Quota.QPS, ov.Quota.QPS)
+ override(ctx, "Quota.Burst", &cfg.Quota.Burst, ov.Quota.Burst)
+ override(ctx, "Quota.MaxEntries", &cfg.Quota.MaxEntries, ov.Quota.MaxEntries)
+ override(ctx, "Quota.RecordOnly", &cfg.Quota.RecordOnly, ov.Quota.RecordOnly)
}
-func overrideString(ctx context.Context, name string, field *string, val string) {
- if val != "" {
+func override[T comparable](ctx context.Context, name string, field *T, val T) {
+ var zero T
+ if val != zero {
*field = val
- log.Infof(ctx, "overriding %s with %q", name, val)
- }
-}
-
-func overrideInt(ctx context.Context, name string, field *int, val int) {
- if val != 0 {
- *field = val
- log.Debugf(ctx, "overriding %s with %d", name, val)
- }
-}
-
-func overrideBool(ctx context.Context, name string, field **bool, val *bool) {
- if val != nil {
- *field = val
- log.Debugf(ctx, "overriding %s with %t", name, *val)
+ log.Infof(ctx, "overriding %s with %v", name, val)
}
}