From 825ca735ba7b92596d85b93061f3d5fb260d7405 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 16 Sep 2024 13:27:42 -0500 Subject: [PATCH 1/2] Update to go 1.23 --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci.yml | 2 +- contactql/inspect.go | 7 +++++-- flows/definition/flow.go | 4 +++- go.mod | 4 ++-- go.sum | 4 ++-- utils/misc.go | 15 +++++++-------- utils/misc_test.go | 6 ------ 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5fa4f9391..cb1827d69 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,6 @@ { "name": "GoFlow", - "image": "mcr.microsoft.com/devcontainers/go:1-1.22-bullseye", + "image": "mcr.microsoft.com/devcontainers/go:1-1.23-bullseye", "features": { "ghcr.io/devcontainers-contrib/features/pandoc:1": { "version": "latest" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f116a0dbb..df0211040 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI on: [push, pull_request] env: - go-version: "1.22.x" + go-version: "1.23.x" jobs: test: name: Test diff --git a/contactql/inspect.go b/contactql/inspect.go index d558112fa..28a3bd88f 100644 --- a/contactql/inspect.go +++ b/contactql/inspect.go @@ -1,6 +1,9 @@ package contactql import ( + "maps" + "slices" + "github.com/nyaruka/goflow/assets" "github.com/nyaruka/goflow/utils" ) @@ -69,8 +72,8 @@ func Inspect(query *ContactQuery) *Inspection { allowAsGroup := !(attributes[AttributeID] || attributes[AttributeStatus] || attributes[AttributeGroup] || attributes[AttributeFlow] || attributes[AttributeHistory]) return &Inspection{ - Attributes: utils.SortedKeys(attributes), - Schemes: utils.SortedKeys(schemes), + Attributes: utils.EnsureNonNil(slices.Sorted(maps.Keys(attributes))), + Schemes: utils.EnsureNonNil(slices.Sorted(maps.Keys(schemes))), Fields: fieldRefs, Groups: groupRefs, AllowAsGroup: allowAsGroup, diff --git a/flows/definition/flow.go b/flows/definition/flow.go index 9c228e801..dd2319a53 100644 --- a/flows/definition/flow.go +++ b/flows/definition/flow.go @@ -3,6 +3,8 @@ package definition import ( "encoding/json" "fmt" + "maps" + "slices" "github.com/Masterminds/semver" "github.com/nyaruka/gocommon/i18n" @@ -268,7 +270,7 @@ func (f *flow) extract() ([]flows.ExtractedTemplate, []flows.ExtractedReference, }) } - return templates, assetRefs, utils.SortedKeys(parentRefs) + return templates, assetRefs, utils.EnsureNonNil(slices.Sorted(maps.Keys(parentRefs))) } // extracts all result specs diff --git a/go.mod b/go.mod index 477cf53e7..449f1ac03 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nyaruka/goflow -go 1.22 +go 1.23 require ( github.com/Masterminds/semver v1.5.0 @@ -9,7 +9,7 @@ require ( github.com/blevesearch/segment v0.9.1 github.com/buger/jsonparser v1.1.1 github.com/go-playground/validator/v10 v10.22.0 - github.com/nyaruka/gocommon v1.57.1 + github.com/nyaruka/gocommon v1.59.0 github.com/sergi/go-diff v1.3.1 github.com/shopspring/decimal v1.4.0 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 2ac3c433b..4934aaeef 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/nyaruka/gocommon v1.57.1 h1:s/9WLZAOUNg0dQHZkgpx8qQMUtNJ2mqzxQhdk1+UBn4= -github.com/nyaruka/gocommon v1.57.1/go.mod h1:wa++Yu/8PEP/HwfvXZrGlKZUCPSJAtSJHeuVsWtLOPM= +github.com/nyaruka/gocommon v1.59.0 h1:XC//IVSOWawBXEZqDiYhqxrIHWo2QPPeCIkAm4n4sY0= +github.com/nyaruka/gocommon v1.59.0/go.mod h1:Upj2DG1iL55YcfF7rve8CRrKGjMaEn0jWUIWbQQgTFQ= github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw= github.com/nyaruka/null/v2 v2.0.3/go.mod h1:OCVeCkCXwrg5/qE6RU0c1oUVZBy+ZDrT+xYg1XSaIWA= github.com/nyaruka/phonenumbers v1.4.0 h1:ddhWiHnHCIX3n6ETDA58Zq5dkxkjlvgrDWM2OHHPCzU= diff --git a/utils/misc.go b/utils/misc.go index 0abbed164..2c8d38466 100644 --- a/utils/misc.go +++ b/utils/misc.go @@ -1,10 +1,7 @@ package utils import ( - "slices" - "golang.org/x/exp/constraints" - "golang.org/x/exp/maps" ) // Set converts a slice to a set (a K > bool map) @@ -16,11 +13,13 @@ func Set[K constraints.Ordered](s []K) map[K]bool { return m } -// SortedKeys returns the keys of a set in lexical order -func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K { - keys := maps.Keys(m) - slices.Sort(keys) - return keys +// Until encoding/json/v2 there's no easy way to ensure nil slices are marshalled as empty arrays +// see https://github.com/golang/go/discussions/63397 +func EnsureNonNil[T any](s []T) []T { + if s == nil { + return []T{} + } + return s } // Typed is an interface of objects that are marshalled as typed envelopes diff --git a/utils/misc_test.go b/utils/misc_test.go index d2f9a93f5..34a725a75 100644 --- a/utils/misc_test.go +++ b/utils/misc_test.go @@ -8,12 +8,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSortedKeys(t *testing.T) { - assert.Equal(t, []string{}, utils.SortedKeys(map[string]bool{})) - assert.Equal(t, []string{"a", "x", "y"}, utils.SortedKeys(map[string]bool{"x": true, "y": true, "a": true})) - assert.Equal(t, []int{3, 5, 6}, utils.SortedKeys(map[int]bool{6: true, 3: true, 5: true})) -} - func TestSet(t *testing.T) { assert.Equal(t, map[string]bool{}, utils.Set[string](nil)) assert.Equal(t, map[string]bool{}, utils.Set([]string{})) From 09a5e28637014811fcde3ae69b00f5f61a55bf62 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 16 Sep 2024 13:53:43 -0500 Subject: [PATCH 2/2] Update dependencies --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 449f1ac03..cff0b6e91 100644 --- a/go.mod +++ b/go.mod @@ -8,14 +8,14 @@ require ( github.com/antlr4-go/antlr/v4 v4.13.1 github.com/blevesearch/segment v0.9.1 github.com/buger/jsonparser v1.1.1 - github.com/go-playground/validator/v10 v10.22.0 + github.com/go-playground/validator/v10 v10.22.1 github.com/nyaruka/gocommon v1.59.0 github.com/sergi/go-diff v1.3.1 github.com/shopspring/decimal v1.4.0 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 - golang.org/x/net v0.27.0 - golang.org/x/text v0.16.0 + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 + golang.org/x/net v0.29.0 + golang.org/x/text v0.18.0 ) require ( @@ -30,8 +30,8 @@ require ( github.com/nyaruka/null/v2 v2.0.3 // indirect github.com/nyaruka/phonenumbers v1.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/sys v0.25.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 4934aaeef..09223db4e 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao= -github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= +github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -56,16 +56,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=