From 1991c87ba9e7a6b2a6fcbc4134b26093831c5e56 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 14 Nov 2012 21:16:00 -0500 Subject: [PATCH] Starting work on go version of chapter 2 examples --- sylvilagus/go/.example-autoenv.env | 2 +- sylvilagus/go/Makefile | 4 ++- .../main.go | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 sylvilagus/go/src/meatballhat.com/sylvilagus-chapter02-hello-world-consumer/main.go diff --git a/sylvilagus/go/.example-autoenv.env b/sylvilagus/go/.example-autoenv.env index 8a69eea..29d73a9 100644 --- a/sylvilagus/go/.example-autoenv.env +++ b/sylvilagus/go/.example-autoenv.env @@ -1,2 +1,2 @@ -export GOPATH="$GOROOT:$HOME/src/box-o-sand/src/sylvilagus" +export GOPATH="$GOROOT:$HOME/src/box-o-sand/src/sylvilagus/go" test -n "$GOROOT" && source "$GOROOT/misc/bash/go" diff --git a/sylvilagus/go/Makefile b/sylvilagus/go/Makefile index f990e65..3d33f75 100644 --- a/sylvilagus/go/Makefile +++ b/sylvilagus/go/Makefile @@ -1,6 +1,8 @@ CLEAN_GOPATH := $(shell echo $(GOPATH) | tr ":" "\n" | grep -v '^$$' | grep -v $(PWD) | tr "\n" ":") GOPATH := $(PWD):$(CLEAN_GOPATH) -PACKAGES := meatballhat.com/sylvilagus-conntest +PACKAGES := \ + meatballhat.com/sylvilagus-conntest \ + meatballhat.com/sylvilagus-chapter02-hello-world-consumer export GOPATH diff --git a/sylvilagus/go/src/meatballhat.com/sylvilagus-chapter02-hello-world-consumer/main.go b/sylvilagus/go/src/meatballhat.com/sylvilagus-chapter02-hello-world-consumer/main.go new file mode 100644 index 0000000..eb58ecf --- /dev/null +++ b/sylvilagus/go/src/meatballhat.com/sylvilagus-chapter02-hello-world-consumer/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "log" +) + +import ( + "github.com/streadway/amqp" +) + +func main() { + connection, err := amqp.Dial("amqp://guest:guest@localhost:5672") + if err != nil { + log.Fatal("Failed to connect!: ", err) + } + + defer connection.Close() + + channel, err := connection.Channel() + if err != nil { + log.Fatal("Failed to get channel!: ", err) + } + + err = channel.ExchangeDeclare("hello-exchange", "direct", true, false, false, false, nil) + if err != nil { + log.Fatal("Failed to declare exchange!: ", err) + } + + err = channel.QueueBind("hello-queue", "hola", "hello-exchange", false, nil) + if err != nil { + log.Fatal("Failed to bind to queue!: ", err) + } +}