Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20
- name: Set up Go 1.24
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.24.x
id: go

- name: Set up Redis
Expand Down
8 changes: 4 additions & 4 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

// Set populates the value of a single string key in cache,
// and sets an expiration for the cache key (in seconds).
func Set(key string, value string, expirationSeconds time.Duration) (interface{}, error) {
func Set(key string, value string, expirationSeconds time.Duration) (any, error) {
set := client.Set(key, value, expirationSeconds)

if set.Err() != nil {
Expand All @@ -76,9 +76,9 @@

// SetMap takes a map of key-value pairs and populates this in a hash-map cache value,
// and sets an expiration for the cache key (in seconds).
func SetMap(key string, obj map[string]string, expiration time.Duration) (interface{}, error) {
func SetMap(key string, obj map[string]string, expiration time.Duration) (any, error) {

imap := make(map[string]interface{})
imap := make(map[string]any)
for k, v := range obj {
imap[k] = v
}
Expand All @@ -91,7 +91,7 @@
return pipe.Exec()
}

func SetMapInterface(key string, obj map[string]interface{}, expiration time.Duration) (interface{}, error) {
func SetMapInterface(key string, obj map[string]any, expiration time.Duration) (any, error) {

Check failure on line 94 in cache/cache.go

View workflow job for this annotation

GitHub Actions / build

exported function SetMapInterface should have comment or be unexported
pipe := client.Pipeline()

pipe.HMSet(key, obj)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/skuid/spec

go 1.20
go 1.24

require (
github.com/DataDog/datadog-go v3.7.2+incompatible
github.com/go-redis/cache v6.4.0+incompatible
github.com/go-redis/redis v6.15.8+incompatible
github.com/satori/go.uuid v1.2.0
github.com/gofrs/uuid/v5 v5.4.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.2.1
github.com/stretchr/testify v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/go-redis/cache v6.4.0+incompatible h1:ZaeoZofvBZmMr8ZKxzFDmkoRTSp8sxH
github.com/go-redis/cache v6.4.0+incompatible/go.mod h1:XNnMdvlNjcZvHjsscEozHAeOeSE5riG9Fj54meG4WT4=
github.com/go-redis/redis v6.15.8+incompatible h1:BKZuG6mCnRj5AOaWJXoCgf6rqTYnYJLe4en2hxT7r9o=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0=
github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -67,8 +69,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
70 changes: 35 additions & 35 deletions mapvalue/mapvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"reflect"
"strings"

uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid/v5"
)

func IsString(sourceMap map[string]interface{}, key string) error {
func IsString(sourceMap map[string]any, key string) error {

Check failure on line 12 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function IsString should have comment or be unexported
// Check that key exists in map
val, ok := sourceMap[key]
if !ok {
Expand All @@ -24,44 +24,44 @@
return nil
}

func String(sourceMap map[string]interface{}, key string) string {
func String(sourceMap map[string]any, key string) string {

Check failure on line 27 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function String should have comment or be unexported
valAsString, ok := sourceMap[key].(string)
if !ok {
return ""
}
return valAsString
}
func Bool(sourceMap map[string]interface{}, key string, deflt bool) bool {
func Bool(sourceMap map[string]any, key string, deflt bool) bool {

Check failure on line 34 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function Bool should have comment or be unexported
valAsBool, ok := sourceMap[key].(bool)
if !ok {
return deflt
}
return valAsBool
}
func Integer(sourceMap map[string]interface{}, key string) int {
func Integer(sourceMap map[string]any, key string) int {

Check failure on line 41 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function Integer should have comment or be unexported
valAsFloat, ok := sourceMap[key].(float64)
if !ok {
return 0
}
return int(valAsFloat)
}

func IsMapSlice(sourceMap map[string]interface{}, key string) error {
func IsMapSlice(sourceMap map[string]any, key string) error {

Check failure on line 49 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function IsMapSlice should have comment or be unexported
// Check that key exists in map
val, ok := sourceMap[key]
if !ok {
return fmt.Errorf("%s must be provided", key)
}

// Check that value of key is a slice
valAsSlice, ok := val.([]interface{})
valAsSlice, ok := val.([]any)
if !ok {
return fmt.Errorf("%s found with wrong type: expected JSON array", key)
}

// Check that the value of each element is a map
for index, nestedValue := range valAsSlice {
_, ok = nestedValue.(map[string]interface{})
_, ok = nestedValue.(map[string]any)
if !ok {
return fmt.Errorf("Object at index %d in array found with wrong type: expected JSON object", index)
}
Expand All @@ -70,33 +70,33 @@
return nil
}

func MapSlice(sourceMap map[string]interface{}, key string) []map[string]interface{} {
var valAsMapSlice []map[string]interface{}
// The type switch statement here complicates things, but it allows us to handle unmarshaled []interface{} slices
// as well as already strongly-typed []map[string]interface{}, without worrying about the underlying abstraction.
func MapSlice(sourceMap map[string]any, key string) []map[string]any {

Check failure on line 73 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function MapSlice should have comment or be unexported
var valAsMapSlice []map[string]any
// The type switch statement here complicates things, but it allows us to handle unmarshaled []any slices
// as well as already strongly-typed []map[string]any, without worrying about the underlying abstraction.
switch sourceMap[key].(type) {
case []interface{}:
// If sourceMap has the type []interface{}, then cast each value into a more strongly typed container.
temp := sourceMap[key].([]interface{})
valAsMapSlice = make([]map[string]interface{}, len(temp))
case []any:
// If sourceMap has the type []any, then cast each value into a more strongly typed container.
temp := sourceMap[key].([]any)
valAsMapSlice = make([]map[string]any, len(temp))
for i, v := range temp {
castVal, ok := v.(map[string]interface{})
castVal, ok := v.(map[string]any)
if !ok {
return []map[string]interface{}{}
return []map[string]any{}
}
valAsMapSlice[i] = castVal
}
case []map[string]interface{}:
// If sourceMap[key] is already typed as []map[string]interface{}, then we're fine and can proceed without casting each value.
valAsMapSlice = sourceMap[key].([]map[string]interface{})
case []map[string]any:
// If sourceMap[key] is already typed as []map[string]any, then we're fine and can proceed without casting each value.
valAsMapSlice = sourceMap[key].([]map[string]any)
default:
return []map[string]interface{}{}
return []map[string]any{}
}
return valAsMapSlice
}

func StringSlice(sourceMap map[string]interface{}, key string) []string {
valAsSlice, ok := sourceMap[key].([]interface{})
func StringSlice(sourceMap map[string]any, key string) []string {

Check failure on line 98 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function StringSlice should have comment or be unexported
valAsSlice, ok := sourceMap[key].([]any)
if !ok {
return []string{}
}
Expand All @@ -111,7 +111,7 @@
return valAsStringSlice
}

func CastInterface(in interface{}, out interface{}) error {
func CastInterface(in any, out any) error {

Check failure on line 114 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function CastInterface should have comment or be unexported
if reflect.ValueOf(out).Kind() != reflect.Ptr {
return fmt.Errorf("out must be a pointer")
}
Expand All @@ -127,26 +127,26 @@
return err
}

func IsMap(sourceMap map[string]interface{}, key string) error {
func IsMap(sourceMap map[string]any, key string) error {

Check failure on line 130 in mapvalue/mapvalue.go

View workflow job for this annotation

GitHub Actions / build

exported function IsMap should have comment or be unexported
// Check that key exists in map
val, ok := sourceMap[key]
if !ok {
return fmt.Errorf("%s must be provided", key)
}

// Check that value of key is a map
_, ok = val.(map[string]interface{})
_, ok = val.(map[string]any)
if !ok {
return fmt.Errorf("%s found with wrong type: expected JSON object", key)
}

return nil
}

func Map(sourceMap map[string]interface{}, key string) map[string]interface{} {
val, ok := sourceMap[key].(map[string]interface{})
func Map(sourceMap map[string]any, key string) map[string]any {
val, ok := sourceMap[key].(map[string]any)
if !ok {
return map[string]interface{}{}
return map[string]any{}
}
return val
}
Expand Down Expand Up @@ -174,8 +174,8 @@
return err == nil
}

func CopyMap(in map[string]interface{}) map[string]interface{} {
out := make(map[string]interface{})
func CopyMap(in map[string]any) map[string]any {
out := make(map[string]any)

for k, v := range in {
out[k] = v
Expand All @@ -190,7 +190,7 @@

// CombineStructWithMap takes a map and adds its values into the struct behind an interface,
// creating a new struct of that type
func CombineStructWithMap(s interface{}, m map[string]interface{}) (interface{}, error) {
func CombineStructWithMap(s any, m map[string]any) (any, error) {
typeof := reflect.TypeOf(s)
newval := reflect.New(typeof).Elem()
sourceval := reflect.ValueOf(s)
Expand All @@ -208,7 +208,7 @@

// setMaybe will take a map, an array of keys, a default reflect.Value, and a val *reflect.Value
// If any of the keys are in map m, and the type matches, it will set val to m[name], otherwise default.
func setMaybe(m map[string]interface{}, names []string, defaultVal reflect.Value, val *reflect.Value) {
func setMaybe(m map[string]any, names []string, defaultVal reflect.Value, val *reflect.Value) {
for _, name := range names {
if mf, ok := m[name]; ok && val.Type() == reflect.TypeOf(mf) && val.CanSet() {
val.Set(reflect.ValueOf(mf))
Expand All @@ -218,7 +218,7 @@
val.Set(defaultVal)
}

func GetValue(in interface{}, key string) (value string, err error) {
func GetValue(in any, key string) (value string, err error) {
valOf := reflect.ValueOf(in)
err = fmt.Errorf("key not found")

Expand Down
Loading