From 511c6cb171036aa74ca711cc8c8ed7d4924c4196 Mon Sep 17 00:00:00 2001 From: Peter Kleiweg Date: Wed, 24 Mar 2021 22:50:25 +0100 Subject: [PATCH] github.com/pborman/uuid -> github.com/google/uuid --- examples/go.mod | 4 ++-- examples/go.sum | 2 -- examples/intface/intface.go | 21 ++++++++++++--------- examples/kvmsg/kvmsg.go | 5 +++-- examples/titanic.go | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 7c33356..11d23a2 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -5,6 +5,6 @@ go 1.16 replace github.com/pebbe/zmq4 => ../ require ( - github.com/pborman/uuid v1.2.1 - github.com/pebbe/zmq4 v0.0.0-00010101000000-000000000000 // indirect + github.com/google/uuid v1.0.0 + github.com/pebbe/zmq4 v0.0.0-00010101000000-000000000000 ) diff --git a/examples/go.sum b/examples/go.sum index c329b5f..db2574a 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,4 +1,2 @@ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw= -github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= diff --git a/examples/intface/intface.go b/examples/intface/intface.go index 7bab494..5d38ad5 100644 --- a/examples/intface/intface.go +++ b/examples/intface/intface.go @@ -5,7 +5,7 @@ package intface import ( zmq "github.com/pebbe/zmq4" - "github.com/pborman/uuid" + "github.com/google/uuid" "bytes" "errors" @@ -73,8 +73,9 @@ const ( // We have a constructor for the peer class: func new_peer(uuid uuid.UUID) (peer *peer_t) { + uuid_bytes, _ := uuid.MarshalBinary() peer = &peer_t{ - uuid_bytes: []byte(uuid), + uuid_bytes: uuid_bytes, uuid_string: uuid.String(), } return @@ -127,13 +128,14 @@ func new_agent() (agent *agent_t) { udp, _ := zmq.NewSocket(zmq.PAIR) udp.Connect("inproc://udp") - uuid := uuid.NewRandom() + uuID := uuid.New() + uuid_bytes, _ := uuID.MarshalBinary() agent = &agent_t{ pipe: pipe, udp: udp, conn: conn, - uuid_bytes: []byte(uuid), - uuid_string: uuid.String(), + uuid_bytes: uuid_bytes, + uuid_string: uuID.String(), peers: make(map[string]*peer_t), } @@ -172,13 +174,14 @@ func (agent *agent_t) handle_beacon() (err error) { } // If we got a UUID and it's not our own beacon, we have a peer - uuid := uuid.UUID(msg[0]) - if bytes.Compare(uuid, agent.uuid_bytes) != 0 { + uuid_bytes := []byte(msg[0]) + if bytes.Compare(uuid_bytes, agent.uuid_bytes) != 0 { // Find or create peer via its UUID string - uuid_string := uuid.String() + uuID, _ := uuid.ParseBytes(uuid_bytes) + uuid_string := uuID.String() peer, ok := agent.peers[uuid_string] if !ok { - peer = new_peer(uuid) + peer = new_peer(uuID) agent.peers[uuid_string] = peer // Report peer joined the network diff --git a/examples/kvmsg/kvmsg.go b/examples/kvmsg/kvmsg.go index d19e38d..348545d 100644 --- a/examples/kvmsg/kvmsg.go +++ b/examples/kvmsg/kvmsg.go @@ -4,7 +4,7 @@ package kvmsg import ( zmq "github.com/pebbe/zmq4" - "github.com/pborman/uuid" + "github.com/google/uuid" "errors" "fmt" @@ -185,7 +185,8 @@ func (kvmsg *Kvmsg) GetUuid() (uuid string, err error) { // Sets the UUID to a random generated value func (kvmsg *Kvmsg) SetUuid() { - kvmsg.frame[frame_UUID] = string(uuid.NewRandom()) // raw 16 bytes + b, _ := uuid.New().MarshalBinary() + kvmsg.frame[frame_UUID] = string(b) // raw 16 bytes kvmsg.present[frame_UUID] = true } diff --git a/examples/titanic.go b/examples/titanic.go index cb32ca6..1660cf2 100644 --- a/examples/titanic.go +++ b/examples/titanic.go @@ -8,7 +8,7 @@ package main import ( "github.com/pebbe/zmq4/examples/mdapi" - "github.com/pborman/uuid" + "github.com/google/uuid" "fmt" "io/ioutil" @@ -53,7 +53,7 @@ func TitanicRequest(chRequest chan<- string) { os.MkdirAll(TITANIC_DIR, 0700) // Generate UUID and save message to disk - uuid := uuid.New() + uuid := uuid.New().String() file, err := os.Create(RequestFilename(uuid)) fmt.Fprint(file, strings.Join(request, "\n")) file.Close()