From d1f8e193ceb8dc135e6bf49d272109f6ac28c79c Mon Sep 17 00:00:00 2001 From: German Zapata Date: Mon, 1 Dec 2025 12:47:34 -0500 Subject: [PATCH 1/3] Changed the uuid library and refactor interface to any --- cache/cache.go | 8 ++--- go.mod | 2 +- go.sum | 4 +-- mapvalue/mapvalue.go | 72 +++++++++++++++++++-------------------- mapvalue/mapvalue_test.go | 56 +++++++++++++++--------------- middlewares/context.go | 10 +++--- redis/client.go | 4 +-- redis/client_test.go | 2 +- 8 files changed, 79 insertions(+), 79 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 2b4d27d..266a0d6 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -63,7 +63,7 @@ func GetMap(key string) (map[string]string, error) { // 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 { @@ -76,9 +76,9 @@ func Set(key string, value string, expirationSeconds time.Duration) (interface{} // 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 } @@ -91,7 +91,7 @@ func SetMap(key string, obj map[string]string, expiration time.Duration) (interf 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) { pipe := client.Pipeline() pipe.HMSet(key, obj) diff --git a/go.mod b/go.mod index 89f496f..be18e6e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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/google/uuid v1.6.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.2.1 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index 75a72cf..d5c94f0 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -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= diff --git a/mapvalue/mapvalue.go b/mapvalue/mapvalue.go index 4d9aedc..fd9a031 100644 --- a/mapvalue/mapvalue.go +++ b/mapvalue/mapvalue.go @@ -6,10 +6,10 @@ import ( "reflect" "strings" - uuid "github.com/satori/go.uuid" + "github.com/google/uuid" ) -func IsString(sourceMap map[string]interface{}, key string) error { +func IsString(sourceMap map[string]any, key string) error { // Check that key exists in map val, ok := sourceMap[key] if !ok { @@ -24,21 +24,21 @@ func IsString(sourceMap map[string]interface{}, key string) error { return nil } -func String(sourceMap map[string]interface{}, key string) string { +func String(sourceMap map[string]any, key string) string { 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 { 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 { valAsFloat, ok := sourceMap[key].(float64) if !ok { return 0 @@ -46,7 +46,7 @@ func Integer(sourceMap map[string]interface{}, key string) int { return int(valAsFloat) } -func IsMapSlice(sourceMap map[string]interface{}, key string) error { +func IsMapSlice(sourceMap map[string]any, key string) error { // Check that key exists in map val, ok := sourceMap[key] if !ok { @@ -54,14 +54,14 @@ func IsMapSlice(sourceMap map[string]interface{}, key string) error { } // 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) } @@ -70,33 +70,33 @@ func IsMapSlice(sourceMap map[string]interface{}, key string) error { 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 { + 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 { + valAsSlice, ok := sourceMap[key].([]any) if !ok { return []string{} } @@ -111,7 +111,7 @@ func StringSlice(sourceMap map[string]interface{}, key string) []string { return valAsStringSlice } -func CastInterface(in interface{}, out interface{}) error { +func CastInterface(in any, out any) error { if reflect.ValueOf(out).Kind() != reflect.Ptr { return fmt.Errorf("out must be a pointer") } @@ -127,7 +127,7 @@ func CastInterface(in interface{}, out interface{}) error { return err } -func IsMap(sourceMap map[string]interface{}, key string) error { +func IsMap(sourceMap map[string]any, key string) error { // Check that key exists in map val, ok := sourceMap[key] if !ok { @@ -135,7 +135,7 @@ func IsMap(sourceMap map[string]interface{}, key string) error { } // 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) } @@ -143,10 +143,10 @@ func IsMap(sourceMap map[string]interface{}, key string) error { 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 } @@ -170,12 +170,12 @@ func StringSliceContainsKeyCaseInsensitive(items []string, item string) (bool, s } func IsValidUUID(u string) bool { - _, err := uuid.FromString(u) + _, err := uuid.Parse(u) 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 @@ -190,7 +190,7 @@ func Pop(slice []string) (string, []string) { // 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) @@ -208,7 +208,7 @@ func CombineStructWithMap(s interface{}, m map[string]interface{}) (interface{}, // 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)) @@ -218,7 +218,7 @@ func setMaybe(m map[string]interface{}, names []string, defaultVal reflect.Value 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") diff --git a/mapvalue/mapvalue_test.go b/mapvalue/mapvalue_test.go index 6ee44bb..3636202 100644 --- a/mapvalue/mapvalue_test.go +++ b/mapvalue/mapvalue_test.go @@ -7,14 +7,14 @@ import ( ) func TestIsString(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "taco mamacita": "north shore", "stir": "southside", "chili's": []string{"downtown", "near the mall"}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string wantErrorMsg string }{ @@ -48,14 +48,14 @@ func TestIsString(t *testing.T) { } func TestString(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "taco mamacita": "north shore", "stir": "southside", "chili's": []string{"downtown", "near the mall"}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string wantReturn string }{ @@ -85,14 +85,14 @@ func TestString(t *testing.T) { } func TestIsMapSlice(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "restaurants": "main street meats", - "bars": []interface{}{map[string]interface{}{"stir": "southside"}, map[string]interface{}{"mike's": "northshore"}}, - "gyms": []interface{}{"non map interface", map[string]interface{}{"sportsbarn": "downtown"}}, + "bars": []any{map[string]any{"stir": "southside"}, map[string]any{"mike's": "northshore"}}, + "gyms": []any{"non map interface", map[string]any{"sportsbarn": "downtown"}}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string wantErrorMsg string }{ @@ -132,40 +132,40 @@ func TestIsMapSlice(t *testing.T) { } func TestMapSlice(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "restaurants": "main street meats", - "bars": []interface{}{map[string]interface{}{"stir": "southside"}, map[string]interface{}{"mike's": "northshore"}}, - "gyms": []interface{}{"non map interface", map[string]interface{}{"sportsbarn": "downtown"}}, + "bars": []any{map[string]any{"stir": "southside"}, map[string]any{"mike's": "northshore"}}, + "gyms": []any{"non map interface", map[string]any{"sportsbarn": "downtown"}}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string - wantReturn []map[string]interface{} + wantReturn []map[string]any }{ { "Should return value when value found as map slice", places, "bars", - []map[string]interface{}{{"stir": "southside"}, {"mike's": "northshore"}}, + []map[string]any{{"stir": "southside"}, {"mike's": "northshore"}}, }, { "Should return empty slice when value missing", places, "offices", - []map[string]interface{}{}, + []map[string]any{}, }, { "Should return empty slice when value exists with wrong type", places, "restaurants", - []map[string]interface{}{}, + []map[string]any{}, }, { "Should return empty slice when nested value exists with wrong type", places, "gyms", - []map[string]interface{}{}, + []map[string]any{}, }, } for _, c := range cases { @@ -175,13 +175,13 @@ func TestMapSlice(t *testing.T) { } func TestIsMap(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "restaurants": "main street meats", - "bars": map[string]interface{}{"stir": "southside"}, + "bars": map[string]any{"stir": "southside"}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string wantErrorMsg string }{ @@ -215,33 +215,33 @@ func TestIsMap(t *testing.T) { } func TestMap(t *testing.T) { - places := map[string]interface{}{ + places := map[string]any{ "restaurants": "main street meats", - "bars": map[string]interface{}{"stir": "southside"}, + "bars": map[string]any{"stir": "southside"}, } cases := []struct { testDescription string - source map[string]interface{} + source map[string]any key string - wantReturn map[string]interface{} + wantReturn map[string]any }{ { "Should return value when value found as map", places, "bars", - map[string]interface{}{"stir": "southside"}, + map[string]any{"stir": "southside"}, }, { "Should return empty map when value missing", places, "offices", - map[string]interface{}{}, + map[string]any{}, }, { "Should return empty slice when value exists with wrong type", places, "restaurants", - map[string]interface{}{}, + map[string]any{}, }, } for _, c := range cases { @@ -263,7 +263,7 @@ func TestCombineStructWithMap(t *testing.T) { 19.00, "sock", } - inputMap := map[string]interface{}{ + inputMap := map[string]any{ "Quantity": 1, "Name": "box", } diff --git a/middlewares/context.go b/middlewares/context.go index 562524e..f737519 100644 --- a/middlewares/context.go +++ b/middlewares/context.go @@ -20,7 +20,7 @@ func OrgIDFromContext(ctx context.Context) (string, error) { if u == nil { return "", errors.New("User is not stored in given context") } - orgID, ok := u.(map[string]interface{})["orgID"] + orgID, ok := u.(map[string]any)["orgID"] if !ok { return "", errors.New("OrgID is not stored in given context") } @@ -37,7 +37,7 @@ func SubdomainFromContext(ctx context.Context) (string, error) { if u == nil { return "", errors.New("User is not stored in given context") } - subdomain, ok := u.(map[string]interface{})["subdomain"] + subdomain, ok := u.(map[string]any)["subdomain"] if !ok { return "", errors.New("subdomain is not stored in given context") } @@ -54,7 +54,7 @@ func UserIDFromContext(ctx context.Context) (string, error) { if u == nil { return "", errors.New("User is not stored in given context") } - v, ok := u.(map[string]interface{})["userID"] + v, ok := u.(map[string]any)["userID"] if !ok { return "", errors.New("UserID is not stored in given context") } @@ -72,7 +72,7 @@ func ContextWithUser(ctx context.Context, userID string, orgID string, admin boo // ContextWithSiteAndUserInfo places a user ID value, site Id, site subdomain, and admin bool into a context using the same context user key func ContextWithSiteAndUserInfo(ctx context.Context, userID string, orgID string, subdomain string, admin bool) context.Context { - userValues := map[string]interface{}{ + userValues := map[string]any{ "orgID": orgID, "subdomain": subdomain, "userID": userID, @@ -88,7 +88,7 @@ func IsAdminFromContext(ctx context.Context) bool { return false } - if v, ok := u.(map[string]interface{})["admin"]; !ok || v == false { + if v, ok := u.(map[string]any)["admin"]; !ok || v == false { return false } return true diff --git a/redis/client.go b/redis/client.go index 158ac95..d12f9ac 100644 --- a/redis/client.go +++ b/redis/client.go @@ -35,10 +35,10 @@ func NewStandardRedisClient(options *redis.Options) *redis.Client { func NewStandardRedisCache(options *redis.Options) *cache.Codec { return &cache.Codec{ Redis: NewStandardRedisClient(options), - Marshal: func(v interface{}) ([]byte, error) { + Marshal: func(v any) ([]byte, error) { return msgpack.Marshal(v) }, - Unmarshal: func(b []byte, v interface{}) error { + Unmarshal: func(b []byte, v any) error { return msgpack.Unmarshal(b, v) }, } diff --git a/redis/client_test.go b/redis/client_test.go index 403b7ae..563a347 100644 --- a/redis/client_test.go +++ b/redis/client_test.go @@ -54,7 +54,7 @@ func TestCacheConnectsAsExpected(t *testing.T) { type TestObject struct { TestString string TestNumerical int - SubObject interface{} + SubObject any } cases := []struct { From 14c7103919e7b33b539771742f610ecbc809b1d8 Mon Sep 17 00:00:00 2001 From: German Zapata Date: Tue, 2 Dec 2025 13:54:13 -0500 Subject: [PATCH 2/3] Changed to github.com/gofrs/uuid/v5, updated to go 1.24 --- .github/workflows/ci.yml | 4 ++-- go.mod | 4 ++-- go.sum | 4 ++-- mapvalue/mapvalue.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 854066a..b51cd5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/go.mod b/go.mod index be18e6e..5830c9d 100644 --- a/go.mod +++ b/go.mod @@ -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/google/uuid v1.6.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 diff --git a/go.sum b/go.sum index d5c94f0..c6628e7 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -37,8 +39,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= diff --git a/mapvalue/mapvalue.go b/mapvalue/mapvalue.go index fd9a031..c13c4da 100644 --- a/mapvalue/mapvalue.go +++ b/mapvalue/mapvalue.go @@ -6,7 +6,7 @@ import ( "reflect" "strings" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" ) func IsString(sourceMap map[string]any, key string) error { @@ -170,7 +170,7 @@ func StringSliceContainsKeyCaseInsensitive(items []string, item string) (bool, s } func IsValidUUID(u string) bool { - _, err := uuid.Parse(u) + _, err := uuid.FromString(u) return err == nil } From d23f24d18373e04cd57b1f96f87ff85c7df7c8eb Mon Sep 17 00:00:00 2001 From: German Zapata Date: Tue, 2 Dec 2025 13:57:38 -0500 Subject: [PATCH 3/3] Added a test just in case --- mapvalue/mapvalue_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mapvalue/mapvalue_test.go b/mapvalue/mapvalue_test.go index 3636202..2b4744e 100644 --- a/mapvalue/mapvalue_test.go +++ b/mapvalue/mapvalue_test.go @@ -278,3 +278,28 @@ func TestCombineStructWithMap(t *testing.T) { assert.Equal(t, nil, err) }) } + +func TestIsValidUUID(t *testing.T) { + t.Run("should return true for valid UUIDs", func(t *testing.T) { + validUUIDs := []string{ + "6ba7b810-9dad-11d1-80b4-00c04fd430c8", + "123e4567-e89b-12d3-a456-426614174000", + "00000000-0000-0000-0000-000000000000", + } + for _, uuid := range validUUIDs { + assert.True(t, IsValidUUID(uuid), "Expected valid UUID: %s", uuid) + } + }) + + t.Run("should return false for invalid UUIDs", func(t *testing.T) { + invalidUUIDs := []string{ + "not-a-uuid", + "12345678-1234-1234-1234-1234567890", + "g123e4567-e89b-12d3-a456-426614174000", + "", + } + for _, uuid := range invalidUUIDs { + assert.False(t, IsValidUUID(uuid), "Expected invalid UUID: %s", uuid) + } + }) +}