From 023773f42a0ee6348dd5c3e2a589f725833e47ad Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Thu, 25 Apr 2024 14:40:32 -0700 Subject: [PATCH] require go 1.22, add ENV flag for 2.x breaking changes --- Makefile | 1 + go.mod | 2 +- util/json.go | 9 ++++++++- util/util.go | 7 +++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0a88922..0b458e7 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,7 @@ clean: ## Clean the project, set it up for a new build @mkdir -p packaging/output/upstart @mkdir -p packaging/output/systemd @mkdir -p tmp/linux + @go clean -testcache run: clean generate ## Run Faktory daemon locally FAKTORY_PASSWORD=${PASSWORD} go run cmd/faktory/daemon.go -l debug -e development diff --git a/go.mod b/go.mod index 96944ff..c1fab30 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/contribsys/faktory -go 1.21 +go 1.22 require ( github.com/BurntSushi/toml v0.4.1 diff --git a/util/json.go b/util/json.go index e1de4e7..24a5994 100644 --- a/util/json.go +++ b/util/json.go @@ -5,12 +5,19 @@ import ( "encoding/json" ) +func Must[T any](obj T, err error) T { + if err != nil { + panic(err) + } + return obj +} + var ( // If true, activates encoding/json's Decoder and its UseNumber() // option to preserve number precision. // Defaults to false in Faktory 1.x. // Will default to true in Faktory 2.x - JsonUseNumber bool = false + JsonUseNumber bool = Faktory2Preview ) func JsonUnmarshal(data []byte, target any) error { diff --git a/util/util.go b/util/util.go index cd01467..c8a3e30 100644 --- a/util/util.go +++ b/util/util.go @@ -1,6 +1,7 @@ package util import ( + "cmp" "context" cryptorand "crypto/rand" "encoding/base64" @@ -8,6 +9,7 @@ import ( "math/big" "os" "runtime" + "strconv" "time" ) @@ -20,6 +22,11 @@ const ( maxInt63 = int64(^uint64(0) >> 1) ) +var ( + // Set FAKTORY2_PREVIEW=true to enable breaking changes coming in Faktory 2.0. + Faktory2Preview bool = Must(strconv.ParseBool(cmp.Or(os.Getenv("FAKTORY2_PREVIEW"), "false"))) +) + func Retryable(ctx context.Context, name string, count int, fn func() error) error { var err error for i := 0; i < count; i++ {