diff --git a/d4-goclient.go b/d4-goclient.go index bf3bd40..85c9dde 100644 --- a/d4-goclient.go +++ b/d4-goclient.go @@ -21,7 +21,7 @@ import ( "strings" "time" - uuid "github.com/gofrs/uuid" + d4hash "github.com/D4-project/d4-golang-utils/crypto/hash" ) const ( @@ -258,10 +258,15 @@ func d4loadConfig(d4 *d4S) bool { (*d4).conf = d4params{} (*d4).conf.source = string(readConfFile(d4, "source")) (*d4).conf.destination = string(readConfFile(d4, "destination")) - tmpu, err := uuid.FromString(string(readConfFile(d4, "uuid"))) + tmpu, err := d4hash.FromString(string(readConfFile(d4, "uuid"))) if err != nil { // generate new uuid - (*d4).conf.uuid = generateUUIDv4() + tmp, err := d4hash.NewV4() + (*d4).conf.uuid = tmp.Bytes() + if err != nil { + log.Fatal(err) + } + infof(fmt.Sprintf("UUIDv4: %s\n", (*d4).conf.uuid)) // And push it into the conf file f, err := os.OpenFile((*d4).confdir+"/uuid", os.O_WRONLY, 0666) defer f.Close() @@ -269,7 +274,7 @@ func d4loadConfig(d4 *d4S) bool { log.Fatal(err) } // store as canonical representation - f.WriteString(fmt.Sprintf("%s", uuid.FromBytesOrNil((*d4).conf.uuid)) + "\n") + f.WriteString(fmt.Sprintf("%s", d4hash.FromBytesOrNil((*d4).conf.uuid)) + "\n") } else { (*d4).conf.uuid = tmpu.Bytes() } @@ -467,15 +472,6 @@ func validPort(port string) bool { return true } -func generateUUIDv4() []byte { - uuid, err := uuid.NewV4() - if err != nil { - log.Fatal(err) - } - infof(fmt.Sprintf("UUIDv4: %s\n", uuid)) - return uuid.Bytes() -} - func (d4w *d4Writer) Write(bs []byte) (int, error) { // bs is pb // zero out moving parts of the frame diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d853da9 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/D4-project/d4-goclient + +go 1.12 + +require ( + github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1 + github.com/gofrs/uuid v3.2.0+incompatible +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..63cbe78 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1 h1:X1MWs5hOzsiHje0BdZEU44tz7azlSRnsPYt91COPulE= +github.com/D4-project/d4-golang-utils v0.0.0-20190529140913-8d3df190a4b1/go.mod h1:2rq8KBQnNNDocwc/49cnpaqoQA/komoSHKom7ynvqJc= +github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=