Documentation
¶
Index ¶
Examples ¶
Constants ¶
const (
//HashSize is the length of a hash in bytes
HashSize = 32
)
Variables ¶
var ( // CurrentVersion represents the current global // version of the zerodisk modules CurrentVersion = NewVersion(1, 1, 0, versionLabel("beta-1")) // NilVersion represents the Nil Version. NilVersion = Version{} // CommitHash represents the Git commit hash at built time CommitHash string // BuildDate represents the date when this tool suite was built BuildDate string // DefaultVersion is the default version that can be assumed, // when a version is empty. DefaultVersion = NewVersion(1, 1, 0, nil) )
var ( //NilHash is a hash with only '0'bytes NilHash = NewHash() )
Functions ¶
func LogVersion ¶
func LogVersion()
LogVersion prints the version at log level info meant to log the version at startup of a server
Types ¶
type Hash ¶
type Hash []byte
Hash is just a bytearray of size HashSize
func HashBytes ¶
HashBytes takes a byte slice and returns a hashed version of it.
Example ¶
// given we have two sets of data ...
dataA := []byte("data to hash")
dataB := []byte("other data to hash")
// we can obtain obtain hashes
hexA := zerodisk.HashBytes(dataA)
printHex(hexA)
hexB := zerodisk.HashBytes(dataB)
printHex(hexB)
// we can compare hashes
sameHash := hexA.Equals(hexA)
fmt.Printf("it is %v that hashes are equal\n", sameHash)
sameHash = hexA.Equals(hexB)
fmt.Printf("it is %v that hashes are equal\n", sameHash)
Output: ae1c89d781f63c4dd6c8ec4703b711bed45966af278446749dbe0eed34eaedf3 4154c68e4df38451a009232697d3da08cbc02aa411bb1e03f1006aa046a84bd4 it is true that hashes are equal it is false that hashes are equal
type Hasher ¶
Hasher is the crypto hasher interface used, for all zerodisk crypto-hash purposes, where we want to reuse a hasher for some reason.
func NewHasher ¶
NewHasher returns a new instance of the default hasher used in 0-Disk, using the given key.
Example ¶
// given we have data ...
data := []byte("data to hash")
// we can define a new instance of default hasher
hasher, err := zerodisk.NewHasher()
panicOnError(err)
// hasher is used to hash the data
h := hasher.HashBytes(data)
printHex(h)
Output: ae1c89d781f63c4dd6c8ec4703b711bed45966af278446749dbe0eed34eaedf3
func NewKeyedHasher ¶
NewKeyedHasher returns a new instance of the default keyed hasher used in 0-Disk, using the given key.
Example ¶
// given we have data and key ...
data := []byte("data to hash")
key := []byte("key")
// we can define a new instance of default keyed hasher
hasher, err := zerodisk.NewKeyedHasher(key)
panicOnError(err)
// hasher is used to hash the data
h := hasher.HashBytes(data)
printHex(h)
Output: 5e09ed568017f03f66d6cca8c37272d0c55be86e9c27cf459721037c8fc3b5bb
type Version ¶
type Version struct {
Number VersionNumber `valid:"required"`
Label *VersionLabel `valid:"optional"`
}
Version defines the version information, used by zerodisk services.
func NewVersion ¶
func NewVersion(major, minor, patch uint8, label *VersionLabel) Version
NewVersion creates a new version
Example ¶
// we can define a new version of the zerodisk modules
label := zerodisk.VersionLabel{'b', 'e', 't', 'a', '-', '2'}
ver := zerodisk.NewVersion(2, 3, 4, &label)
fmt.Println(ver)
Output: 2.3.4-beta-2
func VersionFromString ¶
VersionFromString returns a Version object from the string representation
Example ¶
v, err := zerodisk.VersionFromString("1.2.3-alpha")
if err != nil {
panic(err)
}
fmt.Println(v.Number.Major())
fmt.Println(v.Number.Minor())
fmt.Println(v.Number.Patch())
fmt.Println(v.Label)
Output: 1 2 3 alpha
func VersionFromUInt32 ¶
VersionFromUInt32 creates a version from a given uint32 number.
func (Version) Compare ¶
Compare returns an integer comparing this version with another version. { lt=-1 ; eq=0 ; gt=1 }
Example ¶
// given we have several versions of the zerodisk modules versA := zerodisk.NewVersion(2, 3, 4, nil) versB := zerodisk.NewVersion(2, 3, 4, nil) versC := zerodisk.NewVersion(1, 1, 0, nil) // we can compare versions diff := versA.Compare(versB) fmt.Println(diff) diff = versB.Compare(versC) fmt.Println(diff) diff = versC.Compare(versA) fmt.Println(diff)
Output: 0 1 -1
func (Version) MarshalText ¶
MarshalText implements encoding.TextMarshaler.MarshalText
func (*Version) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText
type VersionLabel ¶
type VersionLabel [8]byte
VersionLabel defines an optional version extension, used by zerodisk services.
func (*VersionLabel) String ¶
func (l *VersionLabel) String() string
String returns the string version of this VersionLabel.
type VersionNumber ¶
type VersionNumber uint32
VersionNumber defines the semantic version number, used by zerodisk services.
func (VersionNumber) Major ¶
func (n VersionNumber) Major() uint8
Major returns the Major version of this version number.
func (VersionNumber) Minor ¶
func (n VersionNumber) Minor() uint8
Minor returns the Minor version of this version number.
func (VersionNumber) Patch ¶
func (n VersionNumber) Patch() uint8
Patch returns the Patch version of this version number.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config defines a package used for managing the configuration of 0-Disk services
|
Package config defines a package used for managing the configuration of 0-Disk services |
|
docs
|
|
|
Package errors defines a package used for error handling in 0-Disk.
|
Package errors defines a package used for error handling in 0-Disk. |
|
Package log defines a complete logging API and is to be used for all 0-Disk info/error logging purposes.
|
Package log defines a complete logging API and is to be used for all 0-Disk info/error logging purposes. |
|
nbd
|
|
|
gonbdserver
command
|
|
|
nbdserver
command
|
|
|
Package redisstub is a minimal package providing redis-related (in-memory) implementations meant for testing and dev purposes only.
|
Package redisstub is a minimal package providing redis-related (in-memory) implementations meant for testing and dev purposes only. |
|
tlogclient/examples/send_tlog
command
|
|
|
tlogserver
command
|
|
|
tools
|
|
|
import_file_into_etcd_config
command
|
|
|
key_rename_milestone_6
command
|
|

