Quellcode durchsuchen

Abstract away EnvVar logic into a utility that can adapt to any combination of Getter and Setter implementations. Add QueryParams implementation.

Matt Bolt vor 5 Jahren
Ursprung
Commit
fe853c3bf0
3 geänderte Dateien mit 522 neuen und 110 gelöschten Zeilen
  1. 54 110
      pkg/env/env.go
  2. 34 0
      pkg/util/http.go
  3. 434 0
      pkg/util/mapper/mapper.go

+ 54 - 110
pkg/env/env.go

@@ -2,232 +2,176 @@ package env
 
 import (
 	"os"
-	"strconv"
+
+	"github.com/kubecost/cost-model/pkg/util/mapper"
 )
 
+//--------------------------------------------------------------------------
+//  EnvVar mapper.Map Implementation
+//--------------------------------------------------------------------------
+
+// envMap contains Getter and Setter implementations for environment variables
+type envMap struct{}
+
+// Get returns the value for the provided environment variable
+func (em *envMap) Get(key string) string {
+	return os.Getenv(key)
+}
+
+// Set sets the value for the provided key and returns true if successful. Otherwise,
+// false is returned.
+func (em *envMap) Set(key string, value string) error {
+	return os.Setenv(key, value)
+}
+
+// This PrimitiveMapper implementation leverages os.Getenv() and os.Setenv() to get/set
+// primitive go values as environment variables.
+var envMapper mapper.PrimitiveMap = mapper.NewMapper(&envMap{})
+
+//--------------------------------------------------------------------------
+//  Package Funcs
+//--------------------------------------------------------------------------
+
 // Get parses an string from the environment variable key parameter. If the environment
 // variable is empty, the defaultValue parameter is returned.
 func Get(key string, defaultValue string) string {
-	r := os.Getenv(key)
-	if r == "" {
-		return defaultValue
-	}
-
-	return r
+	return envMapper.Get(key, defaultValue)
 }
 
 // GetInt parses an int from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetInt(key string, defaultValue int) int {
-	r := os.Getenv(key)
-	i, err := strconv.Atoi(r)
-	if err != nil {
-		return defaultValue
-	}
-
-	return i
+	return envMapper.GetInt(key, defaultValue)
 }
 
 // GetInt8 parses an int8 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetInt8(key string, defaultValue int8) int8 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseInt(r, 10, 8)
-	if err != nil {
-		return defaultValue
-	}
-
-	return int8(i)
+	return envMapper.GetInt8(key, defaultValue)
 }
 
 // GetInt16 parses an int16 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetInt16(key string, defaultValue int16) int16 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseInt(r, 10, 16)
-	if err != nil {
-		return defaultValue
-	}
-
-	return int16(i)
+	return envMapper.GetInt16(key, defaultValue)
 }
 
 // GetInt32 parses an int32 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetInt32(key string, defaultValue int32) int32 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseInt(r, 10, 32)
-	if err != nil {
-		return defaultValue
-	}
-
-	return int32(i)
+	return envMapper.GetInt32(key, defaultValue)
 }
 
 // GetInt64 parses an int64 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetInt64(key string, defaultValue int64) int64 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseInt(r, 10, 64)
-	if err != nil {
-		return defaultValue
-	}
-
-	return i
+	return envMapper.GetInt64(key, defaultValue)
 }
 
 // GetUInt parses a uint from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetUInt(key string, defaultValue uint) uint {
-	r := os.Getenv(key)
-	i, err := strconv.ParseUint(r, 10, 32)
-	if err != nil {
-		return defaultValue
-	}
-
-	return uint(i)
+	return envMapper.GetUInt(key, defaultValue)
 }
 
 // GetUInt8 parses a uint8 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetUInt8(key string, defaultValue uint8) uint8 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseUint(r, 10, 8)
-	if err != nil {
-		return defaultValue
-	}
-
-	return uint8(i)
+	return envMapper.GetUInt8(key, defaultValue)
 }
 
 // GetUInt16 parses a uint16 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetUInt16(key string, defaultValue uint16) uint16 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseUint(r, 10, 16)
-	if err != nil {
-		return defaultValue
-	}
-
-	return uint16(i)
+	return envMapper.GetUInt16(key, defaultValue)
 }
 
 // GetUInt32 parses a uint32 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetUInt32(key string, defaultValue uint32) uint32 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseUint(r, 10, 32)
-	if err != nil {
-		return defaultValue
-	}
-
-	return uint32(i)
+	return envMapper.GetUInt32(key, defaultValue)
 }
 
 // GetUInt64 parses a uint64 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetUInt64(key string, defaultValue uint64) uint64 {
-	r := os.Getenv(key)
-	i, err := strconv.ParseUint(r, 10, 64)
-	if err != nil {
-		return defaultValue
-	}
-
-	return uint64(i)
+	return envMapper.GetUInt64(key, defaultValue)
 }
 
 // GetFloat32 parses a float32 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetFloat32(key string, defaultValue float32) float32 {
-	r := os.Getenv(key)
-	f, err := strconv.ParseFloat(r, 32)
-	if err != nil {
-		return defaultValue
-	}
-
-	return float32(f)
+	return envMapper.GetFloat32(key, defaultValue)
 }
 
 // GetFloat64 parses a float64 from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetFloat64(key string, defaultValue float64) float64 {
-	r := os.Getenv(key)
-	f, err := strconv.ParseFloat(r, 64)
-	if err != nil {
-		return defaultValue
-	}
-
-	return f
+	return envMapper.GetFloat64(key, defaultValue)
 }
 
 // GetBool parses a bool from the environment variable key parameter. If the environment
 // variable is empty or fails to parse, the defaultValue parameter is returned.
 func GetBool(key string, defaultValue bool) bool {
-	r := os.Getenv(key)
-	b, err := strconv.ParseBool(r)
-	if err != nil {
-		return defaultValue
-	}
-
-	return b
+	return envMapper.GetBool(key, defaultValue)
 }
 
 // Set sets the environment variable for the key provided using the value provided.
 func Set(key string, value string) error {
-	return os.Setenv(key, value)
+	return envMapper.Set(key, value)
 }
 
 // SetInt sets the environment variable to a string formatted int value
 func SetInt(key string, value int) error {
-	return os.Setenv(key, strconv.Itoa(value))
+	return envMapper.SetInt(key, value)
 }
 
 // SetInt8 sets the environment variable to a string formatted int8 value.
 func SetInt8(key string, value int8) error {
-	return os.Setenv(key, strconv.FormatInt(int64(value), 10))
+	return envMapper.SetInt8(key, value)
 }
 
 // SetInt16 sets the environment variable to a string formatted int16 value.
 func SetInt16(key string, value int16) error {
-	return os.Setenv(key, strconv.FormatInt(int64(value), 10))
+	return envMapper.SetInt16(key, value)
 }
 
 // SetInt32 sets the environment variable to a string formatted int32 value.
 func SetInt32(key string, value int32) error {
-	return os.Setenv(key, strconv.FormatInt(int64(value), 10))
+	return envMapper.SetInt32(key, value)
 }
 
 // SetInt64 sets the environment variable to a string formatted int64 value.
 func SetInt64(key string, value int64) error {
-	return os.Setenv(key, strconv.FormatInt(value, 10))
+	return envMapper.SetInt64(key, value)
 }
 
 // SetUInt sets the environment variable to a string formatted uint value
 func SetUInt(key string, value uint) error {
-	return os.Setenv(key, strconv.FormatUint(uint64(value), 10))
+	return envMapper.SetUInt(key, value)
 }
 
 // SetUInt8 sets the environment variable to a string formatted uint8 value
 func SetUInt8(key string, value uint8) error {
-	return os.Setenv(key, strconv.FormatUint(uint64(value), 10))
+	return envMapper.SetUInt8(key, value)
 }
 
 // SetUInt16 sets the environment variable to a string formatted uint16 value
 func SetUInt16(key string, value uint16) error {
-	return os.Setenv(key, strconv.FormatUint(uint64(value), 10))
+	return envMapper.SetUInt16(key, value)
 }
 
 // SetUInt32 sets the environment variable to a string formatted uint32 value
 func SetUInt32(key string, value uint32) error {
-	return os.Setenv(key, strconv.FormatUint(uint64(value), 10))
+	return envMapper.SetUInt32(key, value)
 }
 
 // SetUInt64 sets the environment variable to a string formatted uint64 value
 func SetUInt64(key string, value uint64) error {
-	return os.Setenv(key, strconv.FormatUint(value, 10))
+	return envMapper.SetUInt64(key, value)
 }
 
 // SetBool sets the environment variable to a string formatted bool value.
 func SetBool(key string, value bool) error {
-	return os.Setenv(key, strconv.FormatBool(value))
+	return envMapper.SetBool(key, value)
 }

+ 34 - 0
pkg/util/http.go

@@ -3,9 +3,43 @@ package util
 import (
 	"fmt"
 	"net/http"
+	"net/url"
 	"strings"
+
+	"github.com/kubecost/cost-model/pkg/util/mapper"
 )
 
+//--------------------------------------------------------------------------
+//  QueryParams
+//--------------------------------------------------------------------------
+
+type QueryParams = mapper.PrimitiveMap
+
+// queryParamsMap is mapper.Map adapter for url.Values
+type queryParamsMap struct {
+	values url.Values
+}
+
+// mapper.Getter implementation
+func (qpm *queryParamsMap) Get(key string) string {
+	return qpm.values.Get(key)
+}
+
+// mapper.Setter implementation
+func (qpm *queryParamsMap) Set(key, value string) error {
+	qpm.values.Set(key, value)
+	return nil
+}
+
+// NewQueryParams creates a primitive map using the request query parameters
+func NewQueryParams(values url.Values) QueryParams {
+	return mapper.NewMapper(&queryParamsMap{values})
+}
+
+//--------------------------------------------------------------------------
+//  Package Funcs
+//--------------------------------------------------------------------------
+
 // HeaderString writes the request/response http.Header to a string.
 func HeaderString(h http.Header) string {
 	var sb strings.Builder

+ 434 - 0
pkg/util/mapper/mapper.go

@@ -0,0 +1,434 @@
+package mapper
+
+import (
+	"strconv"
+)
+
+//--------------------------------------------------------------------------
+//  Contracts
+//--------------------------------------------------------------------------
+
+// Getter is an interface that retrieves a string value for a string key
+type Getter interface {
+	Get(key string) string
+}
+
+// Setter is an interface that sets the value of a string key to a string value.
+type Setter interface {
+	Set(key string, value string) error
+}
+
+// Map is an interface that gets and sets the value of string keys to/from
+// string values
+type Map interface {
+	Getter
+	Setter
+}
+
+// PrimitiveMapReader is an implementation contract for an object capable
+// of reading primitive values from a util.Map
+type PrimitiveMapReader interface {
+	// Get parses an string from the map key parameter. If the value
+	// is empty, the defaultValue parameter is returned.
+	Get(key string, defaultValue string) string
+
+	// GetInt parses an int from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetInt(key string, defaultValue int) int
+
+	// GetInt8 parses an int8 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetInt8(key string, defaultValue int8) int8
+
+	// GetInt16 parses an int16 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetInt16(key string, defaultValue int16) int16
+
+	// GetInt32 parses an int32 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetInt32(key string, defaultValue int32) int32
+
+	// GetInt64 parses an int64 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetInt64(key string, defaultValue int64) int64
+
+	// GetUInt parses a uint from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetUInt(key string, defaultValue uint) uint
+
+	// GetUInt8 parses a uint8 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetUInt8(key string, defaultValue uint8) uint8
+
+	// GetUInt16 parses a uint16 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetUInt16(key string, defaultValue uint16) uint16
+
+	// GetUInt32 parses a uint32 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetUInt32(key string, defaultValue uint32) uint32
+
+	// GetUInt64 parses a uint64 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetUInt64(key string, defaultValue uint64) uint64
+
+	// GetFloat32 parses a float32 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetFloat32(key string, defaultValue float32) float32
+
+	// GetFloat64 parses a float64 from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetFloat64(key string, defaultValue float64) float64
+
+	// GetBool parses a bool from the map key parameter. If the value
+	// is empty or fails to parse, the defaultValue parameter is returned.
+	GetBool(key string, defaultValue bool) bool
+}
+
+// PrimitiveMapWriter is an implementation contract for an object capable
+// of write primitive values to a util.Map
+type PrimitiveMapWriter interface {
+	// Set sets the map for the key provided using the value provided.
+	Set(key string, value string) error
+
+	// SetInt sets the map to a string formatted int value
+	SetInt(key string, value int) error
+
+	// SetInt8 sets the map to a string formatted int8 value.
+	SetInt8(key string, value int8) error
+
+	// SetInt16 sets the map to a string formatted int16 value.
+	SetInt16(key string, value int16) error
+
+	// SetInt32 sets the map to a string formatted int32 value.
+	SetInt32(key string, value int32) error
+
+	// SetInt64 sets the map to a string formatted int64 value.
+	SetInt64(key string, value int64) error
+
+	// SetUInt sets the map to a string formatted uint value
+	SetUInt(key string, value uint) error
+
+	// SetUInt8 sets the map to a string formatted uint8 value
+	SetUInt8(key string, value uint8) error
+
+	// SetUInt16 sets the map to a string formatted uint16 value
+	SetUInt16(key string, value uint16) error
+
+	// SetUInt32 sets the map to a string formatted uint32 value
+	SetUInt32(key string, value uint32) error
+
+	// SetUInt64 sets the map to a string formatted uint64 value
+	SetUInt64(key string, value uint64) error
+
+	// SetBool sets the map to a string formatted bool value.
+	SetBool(key string, value bool) error
+}
+
+// PrimitiveMap is capable of reading and writing primitive values
+// to/from a util.Map
+type PrimitiveMap interface {
+	PrimitiveMapReader
+	PrimitiveMapWriter
+}
+
+//--------------------------------------------------------------------------
+//  Go Map Implementation
+//--------------------------------------------------------------------------
+
+// map[string]string adapter
+type goMap struct {
+	m map[string]string
+}
+
+// Get implements mapper.Getter
+func (gm *goMap) Get(key string) string {
+	return gm.m[key]
+}
+
+// Set implements mapper.Setter
+func (gm *goMap) Set(key, value string) error {
+	gm.m[key] = value
+	return nil
+}
+
+// NewMap creates a new mapper.Map implementation
+func NewMap() Map {
+	return &goMap{
+		m: make(map[string]string),
+	}
+}
+
+//--------------------------------------------------------------------------
+//  PrimitiveMap Implementation
+//--------------------------------------------------------------------------
+
+// readOnlyMapper provides Get methods for most primitive go types
+type readOnlyMapper struct {
+	getter Getter
+}
+
+// writeOnlyMapper provides Set methods for most primitive go types
+type writeOnlyMapper struct {
+	setter Setter
+}
+
+// mapper provides Get and Set methods for most primitive go types
+type mapper struct {
+	*readOnlyMapper
+	*writeOnlyMapper
+}
+
+// NewReadOnlyMapper creates a new implementation of a PrimitiveMapReader
+func NewReadOnlyMapper(getter Getter) PrimitiveMapReader {
+	return &readOnlyMapper{getter}
+}
+
+// NewWriteOnlyMapper creates a new implementation of a PrimitiveMapWriter
+func NewWriteOnlyMapper(setter Setter) PrimitiveMapWriter {
+	return &writeOnlyMapper{setter}
+}
+
+// NewMapper creates a new implementation of a PrimitiveMap
+func NewMapper(m Map) PrimitiveMap {
+	return &mapper{
+		readOnlyMapper:  &readOnlyMapper{m},
+		writeOnlyMapper: &writeOnlyMapper{m},
+	}
+}
+
+// NewCompositionMapper creates a new implementation of a PrimitiveMap composed of a
+// custom Getter implementation and Setter implementation
+func NewCompositionMapper(getter Getter, setter Setter) PrimitiveMap {
+	return &mapper{
+		readOnlyMapper:  &readOnlyMapper{getter},
+		writeOnlyMapper: &writeOnlyMapper{setter},
+	}
+}
+
+// Get parses an string from the read-only mapper key parameter. If the value
+// is empty, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) Get(key string, defaultValue string) string {
+	r := rom.getter.Get(key)
+	if r == "" {
+		return defaultValue
+	}
+
+	return r
+}
+
+// GetInt parses an int from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetInt(key string, defaultValue int) int {
+	r := rom.getter.Get(key)
+	i, err := strconv.Atoi(r)
+	if err != nil {
+		return defaultValue
+	}
+
+	return i
+}
+
+// GetInt8 parses an int8 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetInt8(key string, defaultValue int8) int8 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseInt(r, 10, 8)
+	if err != nil {
+		return defaultValue
+	}
+
+	return int8(i)
+}
+
+// GetInt16 parses an int16 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetInt16(key string, defaultValue int16) int16 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseInt(r, 10, 16)
+	if err != nil {
+		return defaultValue
+	}
+
+	return int16(i)
+}
+
+// GetInt32 parses an int32 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetInt32(key string, defaultValue int32) int32 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseInt(r, 10, 32)
+	if err != nil {
+		return defaultValue
+	}
+
+	return int32(i)
+}
+
+// GetInt64 parses an int64 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetInt64(key string, defaultValue int64) int64 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseInt(r, 10, 64)
+	if err != nil {
+		return defaultValue
+	}
+
+	return i
+}
+
+// GetUInt parses a uint from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetUInt(key string, defaultValue uint) uint {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseUint(r, 10, 32)
+	if err != nil {
+		return defaultValue
+	}
+
+	return uint(i)
+}
+
+// GetUInt8 parses a uint8 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetUInt8(key string, defaultValue uint8) uint8 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseUint(r, 10, 8)
+	if err != nil {
+		return defaultValue
+	}
+
+	return uint8(i)
+}
+
+// GetUInt16 parses a uint16 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetUInt16(key string, defaultValue uint16) uint16 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseUint(r, 10, 16)
+	if err != nil {
+		return defaultValue
+	}
+
+	return uint16(i)
+}
+
+// GetUInt32 parses a uint32 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetUInt32(key string, defaultValue uint32) uint32 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseUint(r, 10, 32)
+	if err != nil {
+		return defaultValue
+	}
+
+	return uint32(i)
+}
+
+// GetUInt64 parses a uint64 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetUInt64(key string, defaultValue uint64) uint64 {
+	r := rom.getter.Get(key)
+	i, err := strconv.ParseUint(r, 10, 64)
+	if err != nil {
+		return defaultValue
+	}
+
+	return uint64(i)
+}
+
+// GetFloat32 parses a float32 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetFloat32(key string, defaultValue float32) float32 {
+	r := rom.getter.Get(key)
+	f, err := strconv.ParseFloat(r, 32)
+	if err != nil {
+		return defaultValue
+	}
+
+	return float32(f)
+}
+
+// GetFloat64 parses a float64 from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetFloat64(key string, defaultValue float64) float64 {
+	r := rom.getter.Get(key)
+	f, err := strconv.ParseFloat(r, 64)
+	if err != nil {
+		return defaultValue
+	}
+
+	return f
+}
+
+// GetBool parses a bool from the read-only mapper key parameter. If the value
+// is empty or fails to parse, the defaultValue parameter is returned.
+func (rom *readOnlyMapper) GetBool(key string, defaultValue bool) bool {
+	r := rom.getter.Get(key)
+	b, err := strconv.ParseBool(r)
+	if err != nil {
+		return defaultValue
+	}
+
+	return b
+}
+
+// Set sets the map for the key provided using the value provided.
+func (wom *writeOnlyMapper) Set(key string, value string) error {
+	return wom.setter.Set(key, value)
+}
+
+// SetInt sets the map to a string formatted int value
+func (wom *writeOnlyMapper) SetInt(key string, value int) error {
+	return wom.setter.Set(key, strconv.Itoa(value))
+}
+
+// SetInt8 sets the map to a string formatted int8 value.
+func (wom *writeOnlyMapper) SetInt8(key string, value int8) error {
+	return wom.setter.Set(key, strconv.FormatInt(int64(value), 10))
+}
+
+// SetInt16 sets the map to a string formatted int16 value.
+func (wom *writeOnlyMapper) SetInt16(key string, value int16) error {
+	return wom.setter.Set(key, strconv.FormatInt(int64(value), 10))
+}
+
+// SetInt32 sets the map to a string formatted int32 value.
+func (wom *writeOnlyMapper) SetInt32(key string, value int32) error {
+	return wom.setter.Set(key, strconv.FormatInt(int64(value), 10))
+}
+
+// SetInt64 sets the map to a string formatted int64 value.
+func (wom *writeOnlyMapper) SetInt64(key string, value int64) error {
+	return wom.setter.Set(key, strconv.FormatInt(value, 10))
+}
+
+// SetUInt sets the map to a string formatted uint value
+func (wom *writeOnlyMapper) SetUInt(key string, value uint) error {
+	return wom.setter.Set(key, strconv.FormatUint(uint64(value), 10))
+}
+
+// SetUInt8 sets the map to a string formatted uint8 value
+func (wom *writeOnlyMapper) SetUInt8(key string, value uint8) error {
+	return wom.setter.Set(key, strconv.FormatUint(uint64(value), 10))
+}
+
+// SetUInt16 sets the map to a string formatted uint16 value
+func (wom *writeOnlyMapper) SetUInt16(key string, value uint16) error {
+	return wom.setter.Set(key, strconv.FormatUint(uint64(value), 10))
+}
+
+// SetUInt32 sets the map to a string formatted uint32 value
+func (wom *writeOnlyMapper) SetUInt32(key string, value uint32) error {
+	return wom.setter.Set(key, strconv.FormatUint(uint64(value), 10))
+}
+
+// SetUInt64 sets the map to a string formatted uint64 value
+func (wom *writeOnlyMapper) SetUInt64(key string, value uint64) error {
+	return wom.setter.Set(key, strconv.FormatUint(value, 10))
+}
+
+// SetBool sets the map to a string formatted bool value.
+func (wom *writeOnlyMapper) SetBool(key string, value bool) error {
+	return wom.setter.Set(key, strconv.FormatBool(value))
+}