chore(settings): use generics for helping functions (#1427)

This commit is contained in:
Julio Gutierrez
2023-05-20 20:37:23 +00:00
committed by GitHub
parent 86ec75722a
commit 5200ee5722
33 changed files with 362 additions and 832 deletions

View File

@@ -27,16 +27,16 @@ type Settings struct {
}
func (s *Settings) SetDefaults() {
s.Enabled = helpers.DefaultBool(s.Enabled, false)
s.Enabled = helpers.DefaultPointer(s.Enabled, false)
s.HTTPServer.Address = helpers.DefaultString(s.HTTPServer.Address, "localhost:6060")
const defaultReadTimeout = 5 * time.Minute // for CPU profiling
s.HTTPServer.ReadTimeout = helpers.DefaultDuration(s.HTTPServer.ReadTimeout, defaultReadTimeout)
s.HTTPServer.ReadTimeout = helpers.DefaultNumber(s.HTTPServer.ReadTimeout, defaultReadTimeout)
s.HTTPServer.SetDefaults()
}
func (s Settings) Copy() (copied Settings) {
return Settings{
Enabled: helpers.CopyBoolPtr(s.Enabled),
Enabled: helpers.CopyPointer(s.Enabled),
BlockProfileRate: s.BlockProfileRate,
MutexProfileRate: s.MutexProfileRate,
HTTPServer: s.HTTPServer.Copy(),
@@ -44,16 +44,16 @@ func (s Settings) Copy() (copied Settings) {
}
func (s *Settings) MergeWith(other Settings) {
s.Enabled = helpers.MergeWithBool(s.Enabled, other.Enabled)
s.BlockProfileRate = helpers.MergeWithIntPtr(s.BlockProfileRate, other.BlockProfileRate)
s.MutexProfileRate = helpers.MergeWithIntPtr(s.MutexProfileRate, other.MutexProfileRate)
s.Enabled = helpers.MergeWithPointer(s.Enabled, other.Enabled)
s.BlockProfileRate = helpers.MergeWithPointer(s.BlockProfileRate, other.BlockProfileRate)
s.MutexProfileRate = helpers.MergeWithPointer(s.MutexProfileRate, other.MutexProfileRate)
s.HTTPServer.MergeWith(other.HTTPServer)
}
func (s *Settings) OverrideWith(other Settings) {
s.Enabled = helpers.OverrideWithBool(s.Enabled, other.Enabled)
s.BlockProfileRate = helpers.OverrideWithIntPtr(s.BlockProfileRate, other.BlockProfileRate)
s.MutexProfileRate = helpers.OverrideWithIntPtr(s.MutexProfileRate, other.MutexProfileRate)
s.Enabled = helpers.OverrideWithPointer(s.Enabled, other.Enabled)
s.BlockProfileRate = helpers.OverrideWithPointer(s.BlockProfileRate, other.BlockProfileRate)
s.MutexProfileRate = helpers.OverrideWithPointer(s.MutexProfileRate, other.MutexProfileRate)
s.HTTPServer.OverrideWith(other.HTTPServer)
}