Skip to content

Commit

Permalink
more ConfigMap getters
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Nov 11, 2024
1 parent 081547d commit 88319bd
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions core/server/config.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88319bd

Please sign in to comment.