Updating Go impl to use amqp uri from env

This commit is contained in:
Dan Buch 2012-11-17 08:10:11 -05:00
parent 13d3d28fe3
commit 148cf7ef95
3 changed files with 11 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import (
) )
func main() { func main() {
connection, err := amqp.Dial("amqp://guest:guest@localhost:5672") connection, err := amqp.Dial(sylvilagus.AMQP_URI)
if err != nil { if err != nil {
log.Fatal("Failed to connect!: ", err) log.Fatal("Failed to connect!: ", err)
} }

View File

@ -18,7 +18,7 @@ func main() {
msgBody := string(os.Args[1]) msgBody := string(os.Args[1])
connection, err := amqp.Dial("amqp://guest:guest@localhost:5672") connection, err := amqp.Dial(sylvilagus.AMQP_URI)
if err != nil { if err != nil {
log.Fatal("Failed to connect!: ", err) log.Fatal("Failed to connect!: ", err)
} }

View File

@ -2,12 +2,21 @@ package sylvilagus
import ( import (
"log" "log"
"os"
) )
import ( import (
"github.com/streadway/amqp" "github.com/streadway/amqp"
) )
var AMQP_URI = os.Getenv("SYLVILAGUS_AMQP_URI")
func init() {
if len(AMQP_URI) < 1 {
log.Fatal("SYLVILAGUS_AMQP_URI is not defined!")
}
}
func CreateHelloTopology(connection *amqp.Connection) (*amqp.Channel, error) { func CreateHelloTopology(connection *amqp.Connection) (*amqp.Channel, error) {
channel, err := connection.Channel() channel, err := connection.Channel()
if err != nil { if err != nil {