mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-781 Switch Todoist IDs from `int` to `string` On platforms that convert an `int` to `int32`, like the Raspberry Pi, an `int` is not large enough to store Todoist project IDs. Using a `string` ensures this never becomes a problem. Fixes #781 Signed-off-by: Chris Cummer <chriscummer@me.com>
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
/* -------------------- Map Conversion -------------------- */
|
|
|
|
// MapToStrs takes a map of interfaces and returns a map of strings
|
|
func MapToStrs(aMap map[string]interface{}) map[string]string {
|
|
results := make(map[string]string, len(aMap))
|
|
|
|
for key, val := range aMap {
|
|
results[key] = val.(string)
|
|
}
|
|
|
|
return results
|
|
}
|
|
|
|
/* -------------------- Slice Conversion -------------------- */
|
|
|
|
// IntsToUints takes a slice of ints and returns a slice of uints
|
|
func IntsToUints(slice []int) []uint {
|
|
results := make([]uint, len(slice))
|
|
|
|
for i, val := range slice {
|
|
results[i] = uint(val)
|
|
}
|
|
|
|
return results
|
|
}
|
|
|
|
// ToInts takes a slice of interfaces and returns a slice of ints
|
|
func ToInts(slice []interface{}) []int {
|
|
results := make([]int, len(slice))
|
|
|
|
for i, val := range slice {
|
|
results[i] = val.(int)
|
|
}
|
|
|
|
return results
|
|
}
|
|
|
|
// ToStrs takes a slice of interfaces and returns a slice of strings
|
|
func ToStrs(slice []interface{}) []string {
|
|
results := make([]string, len(slice))
|
|
|
|
for i, val := range slice {
|
|
switch t := val.(type) {
|
|
case int:
|
|
results[i] = strconv.Itoa(t)
|
|
case string:
|
|
results[i] = t
|
|
}
|
|
}
|
|
|
|
return results
|
|
}
|
|
|
|
// ToUints takes a slice of interfaces and returns a slice of ints
|
|
func ToUints(slice []interface{}) []uint {
|
|
results := make([]uint, len(slice))
|
|
|
|
for i, val := range slice {
|
|
results[i] = val.(uint)
|
|
}
|
|
|
|
return results
|
|
}
|