From 88319bd32ad4e215cad25422d556b4537a66d753 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Mon, 11 Nov 2024 17:55:10 -0600 Subject: [PATCH] more ConfigMap getters --- core/server/config.go | 50 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/core/server/config.go b/core/server/config.go index 3d5c8f224764..4af535087d6d 100644 --- a/core/server/config.go +++ b/core/server/config.go @@ -1,6 +1,9 @@ package server -import "strings" +import ( + "strings" + "time" +) // DynamicConfig defines an interface for configuration that can be dynamically // fetched at runtime by an arbitrary key. @@ -44,32 +47,61 @@ func getValue[T any](cfg ConfigMap, key string, def T) any { return res } -// Get implements DynamicConfig. func (c ConfigMap) Get(key string) any { return getValue[any](c, key, nil) } -// GetInt64 implements DynamicConfig. func (c ConfigMap) GetInt64(key string) int64 { return getValue(c, key, int64(0)).(int64) } -// GetSliceOfStringSlices implements DynamicConfig. +func (c ConfigMap) GetUint64(key string) uint64 { + return getValue(c, key, uint64(0)).(uint64) +} + +func (c ConfigMap) GetUint32(key string) uint32 { + return getValue(c, key, uint32(0)).(uint32) +} + +func (c ConfigMap) GetInt32(key string) int32 { + return getValue(c, key, int32(0)).(int32) +} + +func (c ConfigMap) GetFloat64(key string) float64 { + return getValue(c, key, float64(0)).(float64) +} + +func (c ConfigMap) GetInt(key string) int { + return getValue(c, key, 0).(int) +} + +func (c ConfigMap) GetUint(key string) uint { + return getValue(c, key, uint(0)).(uint) +} + func (c ConfigMap) GetSliceOfStringSlices(key string) [][]string { return getValue(c, key, [][]string{}).([][]string) } -// GetString implements DynamicConfig. +func (c ConfigMap) GetSliceOfStrings(key string) []string { + return getValue(c, key, []string{}).([]string) +} + +func (c ConfigMap) GetSliceOfInts(key string) []int { + return getValue(c, key, []int{}).([]int) +} + func (c ConfigMap) GetString(key string) string { return getValue(c, key, "").(string) } -// GetUint64 implements DynamicConfig. -func (c ConfigMap) GetUint64(key string) uint64 { - return getValue(c, key, uint64(0)).(uint64) +func (c ConfigMap) GetBool(key string) bool { + return getValue(c, key, false).(bool) } -var _ DynamicConfig = ConfigMap{} +func (c ConfigMap) GetDuration(key string) time.Duration { + return time.Duration(getValue(c, key, int64(0)).(int64)) +} // ModuleConfigMap is used to specify module configuration. // Keys (and there default values and types) should be set in Config