Moving bulk of amqp play crap into separate lib

in prep for changing the things, introducing more code.
This commit is contained in:
Dan Buch 2012-11-10 18:47:32 -05:00
parent d24efe640b
commit 1ab8d7d42c
3 changed files with 29 additions and 13 deletions

View File

@ -4,12 +4,12 @@ PACKAGES := $(foreach pkg,\
$(shell ls src/meatballhat.com/gotour-artifacts),\ $(shell ls src/meatballhat.com/gotour-artifacts),\
$(patsubst %,meatballhat.com/gotour-artifacts/%,$(pkg))\ $(patsubst %,meatballhat.com/gotour-artifacts/%,$(pkg))\
) )
PACKAGES += meatballhat.com/amqpfun PACKAGES += meatballhat.com/amqpfun-runner
test: build test: build
go test $(PACKAGES) go test $(PACKAGES)
build: deps fmt build: deps
go install $(PACKAGES) go install $(PACKAGES)
fmt: fmt:

View File

@ -0,0 +1,24 @@
package main
import (
"fmt"
"os"
)
import (
"meatballhat.com/amqpfun"
)
const USAGE = "Usage: amqpfun-runner (publish|consume)"
func main() {
if len(os.Args) < 2 {
fmt.Println(USAGE)
os.Exit(1)
}
if os.Args[1] == "publish" {
amqpfun.Publish()
} else if os.Args[1] == "consume" {
amqpfun.Consume()
}
}

View File

@ -1,4 +1,4 @@
package main package amqpfun
import ( import (
"log" "log"
@ -12,7 +12,7 @@ import (
"github.com/streadway/amqp" "github.com/streadway/amqp"
) )
func publish() { func Publish() {
// Connects opens an AMQP connection from the credentials in the URL. // Connects opens an AMQP connection from the credentials in the URL.
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/") conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil { if err != nil {
@ -57,7 +57,7 @@ func publish() {
} }
} }
func consume() { func Consume() {
// Connects opens an AMQP connection from the credentials in the URL. // Connects opens an AMQP connection from the credentials in the URL.
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/") conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil { if err != nil {
@ -183,11 +183,3 @@ func consume() {
// sure to wait for all consumers goroutines to finish before exiting your // sure to wait for all consumers goroutines to finish before exiting your
// process. // process.
} }
func main() {
if os.Args[1] == "publish" {
publish()
} else if os.Args[1] == "consume" {
consume()
}
}