mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
48 lines
800 B
Go
48 lines
800 B
Go
package nonce
|
|
|
|
import (
|
|
"strconv"
|
|
"sync"
|
|
)
|
|
|
|
// Nonce struct holds the nonce value
|
|
type Nonce struct {
|
|
n int64
|
|
m sync.Mutex
|
|
}
|
|
|
|
// Get retrieves the nonce value
|
|
func (n *Nonce) Get() Value {
|
|
n.m.Lock()
|
|
defer n.m.Unlock()
|
|
return Value(n.n)
|
|
}
|
|
|
|
// GetInc increments and returns the value of the nonce
|
|
func (n *Nonce) GetInc() Value {
|
|
n.m.Lock()
|
|
defer n.m.Unlock()
|
|
n.n++
|
|
return Value(n.n)
|
|
}
|
|
|
|
// Set sets the nonce value
|
|
func (n *Nonce) Set(val int64) {
|
|
n.m.Lock()
|
|
n.n = val
|
|
n.m.Unlock()
|
|
}
|
|
|
|
// String returns a string version of the nonce
|
|
func (n *Nonce) String() string {
|
|
return n.Get().String()
|
|
}
|
|
|
|
// Value is a return type for GetValue
|
|
type Value int64
|
|
|
|
// String is a Value method that changes format to a string
|
|
func (v Value) String() string {
|
|
return strconv.FormatInt(int64(v), 10)
|
|
}
|