If you read my post showing how to send SMS messages using Go you know I’ve been spending 2014 learning Go and having tons of fun doing it. My most recent project has been using Go to make and receive phone calls using Twilio. One great thing about working on this is that it required me to learn how to build a basic Go webserver. In this post I’ll show you what I’ve learned and before you know it you’ll be making and receiving phone calls from your Go apps too.

Our Tools

Go running on your local machine

A Twilio Account – Sign up for free!

Ngrok to expose your localhost to Twilio

A Basic Web Server

When a user makes a phone call to your Twilio phone number we ask your server for some basic instructions of what to do with that phone call. In order to do this with Go we need to set up a basic web server. Fortunately Go’s net/http library makes this really easy.

Fire up your favorite text editor and create a new file called main.go. We’ll start it off by declaring our package and importing the net/http package: