Skip to content

Commit

Permalink
added ./examples/go.mod ; removed external dependency from ./go.mod ;…
Browse files Browse the repository at this point in the history
… github.com/pborman/uuid -> github.com/google/uuid
  • Loading branch information
pebbe committed Mar 24, 2021
1 parent 5d1a595 commit 0032878
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
10 changes: 10 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/pebbe/zmq2/examples

go 1.16

replace github.com/pebbe/zmq2 => ../

require (
github.com/google/uuid v1.2.0
github.com/pebbe/zmq2 v0.0.0-00010101000000-000000000000
)
2 changes: 2 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
21 changes: 12 additions & 9 deletions examples/intface/intface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package intface
import (
zmq "github.com/pebbe/zmq2"

"github.com/pborman/uuid"
"github.com/google/uuid"

"bytes"
"errors"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/kvmsg/kvmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package kvmsg
import (
zmq "github.com/pebbe/zmq2"

"github.com/pborman/uuid"
"github.com/google/uuid"

"errors"
"fmt"
Expand Down Expand Up @@ -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

}
Expand Down
4 changes: 2 additions & 2 deletions examples/titanic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package main
import (
"github.com/pebbe/zmq2/examples/mdapi"

"github.com/pborman/uuid"
"github.com/google/uuid"

"fmt"
"io/ioutil"
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/pebbe/zmq2

go 1.16

require github.com/pborman/uuid v1.2.1

0 comments on commit 0032878

Please sign in to comment.