diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6c73ed2..146c7c1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: "1.22.x" + go-version: "1.21.x" - name: Install dependencies run: go get . - name: Vet diff --git a/go.mod b/go.mod index e331b1d..6372916 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/restatedev/sdk-go -go 1.22.0 +go 1.21.0 require ( github.com/golang-jwt/jwt/v5 v5.2.1 diff --git a/internal/rand/rand.go b/internal/rand/rand.go index 946d548..acc5d61 100644 --- a/internal/rand/rand.go +++ b/internal/rand/rand.go @@ -3,7 +3,7 @@ package rand import ( "crypto/sha256" "encoding/binary" - "math/rand/v2" + "math/rand" "github.com/google/uuid" ) @@ -25,10 +25,18 @@ func (r *Rand) UUID() uuid.UUID { return uuid } +func (r *Rand) Float64() float64 { + // use the math/rand/v2 implementation of Float64() which is more correct + // and also matches our TS implementation + return float64(r.Uint64()<<11>>11) / (1 << 53) +} + type Source struct { state [4]uint64 } +var _ rand.Source64 = (*Source)(nil) + func newSource(invocationID []byte) *Source { hash := sha256.New() hash.Write(invocationID) @@ -43,6 +51,12 @@ func newSource(invocationID []byte) *Source { }} } +func (s *Source) Int63() int64 { + return int64(s.Uint64() & ((1 << 63) - 1)) +} + +func (s *Source) Seed(int64) {} + func (s *Source) Uint64() uint64 { result := rotl((s.state[0]+s.state[3]), 23) + s.state[0] diff --git a/internal/rand/rand_test.go b/internal/rand/rand_test.go index 6a91faa..46d6f39 100644 --- a/internal/rand/rand_test.go +++ b/internal/rand/rand_test.go @@ -2,7 +2,7 @@ package rand import ( "encoding/hex" - "math/rand/v2" + "math/rand" "testing" ) diff --git a/reflect.go b/reflect.go index 08a77eb..6469f0a 100644 --- a/reflect.go +++ b/reflect.go @@ -14,10 +14,10 @@ type serviceNamer interface { } var ( - typeOfContext = reflect.TypeFor[Context]() - typeOfObjectContext = reflect.TypeFor[ObjectContext]() - typeOfVoid = reflect.TypeFor[Void]() - typeOfError = reflect.TypeFor[error]() + typeOfContext = reflect.TypeOf((*Context)(nil)).Elem() + typeOfObjectContext = reflect.TypeOf((*ObjectContext)(nil)).Elem() + typeOfVoid = reflect.TypeOf((*Void)(nil)) + typeOfError = reflect.TypeOf((*error)(nil)) ) // Object converts a struct with methods into a Virtual Object where each correctly-typed