Skip to content

Commit

Permalink
Merge pull request #1 from greg-szabo/mircea/uint64
Browse files Browse the repository at this point in the history
added uint64 methods
  • Loading branch information
greg-szabo authored Oct 9, 2019
2 parents 2d25966 + e3b8e25 commit 3105932
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 38 deletions.
38 changes: 0 additions & 38 deletions Gopkg.toml

This file was deleted.

25 changes: 25 additions & 0 deletions ddb/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@ func (m *Mutex) GetValueInt64() int64 {
return result
}

// GetValueUint64 gets the value from the Mutex and returns it as an uint64.
//
// It does not check if the Mutex was locked beforehand. An unlocked Mutex will return an out-of-sync result.
func (m *Mutex) GetValueUint64() uint64 {

if m.value == "" {
return 0
}

result, err := strconv.ParseUint(m.value, 10, 64)
if err != nil {
panic(err.Error())
}

return result
}

// SetValueInt64 sets the int64 value in the Mutex. It does not check if the Mutex was locked beforehand. It does not write
// the value into the database. The value is written to the database during Unlock.
//
Expand All @@ -328,6 +345,14 @@ func (m *Mutex) SetValueInt64(value int64) {
m.value = strconv.FormatInt(value, 10)
}

// SetValueUint64 sets the uint64 value in the Mutex. It does not check if the Mutex was locked beforehand. It does not write
// the value into the database. The value is written to the database during Unlock.
//
// See example(s) at GetValueUint64
func (m *Mutex) SetValueUint64(value uint64) {
m.value = strconv.FormatUint(value, 10)
}

// GetValueString gets the value from the Mutex and returns it as a string.
//
// It does not check if the Mutex was locked beforehand. An unlocked Mutex will return an out-of-sync result.
Expand Down
7 changes: 7 additions & 0 deletions ddb/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,20 @@ func Test_ValueTests(t *testing.T) {
TableName := fmt.Sprintf("Test-Values-%d", time.Now().Unix())
m := Mutex{DDBTableName: TableName}
testValueInt64 := time.Now().Unix()
testValueUint64 := testValueInt64 + 5
assert.NotPanics(t, m.Lock)
m.SetValueInt64(testValueInt64)
assert.Equal(t, m.GetValueInt64(), testValueInt64)
assert.Equal(t, m.GetValueString(), strconv.FormatInt(testValueInt64, 10))
m.SetValueUint64(uint64(testValueUint64))
assert.Equal(t, m.GetValueUint64(), uint64(testValueUint64))
assert.Equal(t, m.GetValueString(), strconv.FormatUint(uint64(testValueUint64), 10))
m.SetValueString(strconv.FormatInt(testValueInt64+1, 10))
assert.Equal(t, m.GetValueInt64(), testValueInt64+1)
assert.Equal(t, m.GetValueString(), strconv.FormatInt(testValueInt64+1, 10))
m.SetValueString(strconv.FormatUint(uint64(testValueUint64+2), 10))
assert.Equal(t, m.GetValueUint64(), uint64(testValueUint64+2))
assert.Equal(t, m.GetValueString(), strconv.FormatUint(uint64(testValueUint64+2), 10))
assert.NotPanics(t, m.Unlock)
DeleteTable(m)
}
Expand Down
2 changes: 2 additions & 0 deletions dsync/dsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ type Locker interface {
Lock()
Unlock()
GetValueInt64() int64
GetValueUint64() uint64
SetValueInt64(value int64)
SetValueUint64(value uint64)
GetValueString() string
SetValueString(value string)
}
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/greg-szabo/dsync

go 1.13

require (
github.com/aws/aws-sdk-go v1.25.8
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20191007182048-72f939374954 // indirect
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/aws/aws-sdk-go v1.25.8 h1:n7I+HUUXjun2CsX7JK+1hpRIkZrlKhd3nayeb+Xmavs=
github.com/aws/aws-sdk-go v1.25.8/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20191007182048-72f939374954 h1:JGZucVF/L/TotR719NbujzadOZ2AgnYlqphQGHDCKaU=
golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit 3105932

Please sign in to comment.