We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Connect

Let's scaffold the Peril project! Fork and then clone starter code from GitHub and move it somewhere on your machine. We will use this project for the rest of the course.

The starter code contains a few interesting things

  • The internal/gamelogic package which contains the game logic for the Peril game.
  • The internal/routing package which contains some routing constants for the game.
  • Stubs of the cmd/client and cmd/server packages, which are main packages that run the client and server for the game.
  • The rabbit.sh script: a convenience for starting and stopping RabbitMQ with Docker. You can run:
    • ./rabbit.sh start to start RabbitMQ
    • ./rabbit.sh stop to stop it
    • ./rabbit.sh logs to view the server logs

Assignment

go get github.com/rabbitmq/amqp091-go
import (
    amqp "github.com/rabbitmq/amqp091-go"
)

To test your code, use the script to start a RabbitMQ server with Docker in the background:

./rabbit.sh start

Once it's running, open a new terminal and run your server:

go run ./cmd/server

You should see your message that the connection was successful. Press Ctrl+C to exit the program and see the shutdown message.

Tip

The Go standard library has a package called os/signal that you can use to listen for signals. Here's an example of how you can listen for a signal:

// wait for ctrl+c
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
<-signalChan