- Currently this server is hosted on a raspberry pi, running 24/7 as my personal API and email server!
- I wanted a server that I could completely customize to my current needs, and have the scalability to fulfil my future needs!
- The API can be accessed at
api.alexmontague.ca
try pinging/resume
for a JSON representation of my resume! - Using this server as an opportunity to learn GoLang and networking stuff!
If you want to spin up a similar Golang API, heres how you run mine
- Clone the repo
- Make sure Go is installed
- I suggest also having a session manager installed like tmux to persist sessions after sshing into the server (as I leave the pi running 24/7)
- SSH into your server if applicable
- Start a new session
tmux new -s API
- Run the server using
go run main.go
- The server will log endpoint info to stdout
The following steps are configuring the server as it runs on my personal network
I use nginx as a reverse proxy so I can direct requests from my default ip to the server running on my specific port
- Install nginx
- Start nginx and restart on reboots
sudo systemctl start nginx && sudo systemctl enable nginx
- Create an nginx config file in
/etc/nginx/conf.d
named whatever you want. I have this config namedgoApi.conf
- In the config file paste this:
server {
listen 80;
listen [::]:80;
server_name <EXTERNAL_DOMAIN>;
location / {
proxy_pass http://localhost:<PORT>/;
}
}
Replace <EXTERNAL_DOMAIN>
with your server's domain or ip
Replace <PORT>
with the local port your server is running on. In my case it is 8080
- Test the config file to make sure there are no errors:
sudo nginx -t
- If everything looks good, restart nginx
sudo nginx -s reload
I also use a shell script to update my api domain record, as it is hosted through my dynamic home external ip. Here is how you set that up!
- Note: This implementation is for GoDaddy Domains. If your domain provider has an API, you would need to make a few changes
- Create a GoDaddy API Key
- Store the credentials in
/etc/environment
asGODADDY_KEY
andGODADDY_SECRET
respectfully so the cron can access these environment vars - Set up the cron using
crontab -e
and adding the cron*/10 * * * * ~/go/src/api.alexmontague.ca/updateIP.sh >> ~/Documents/cronAPI.log 2>&1
3.b) You do not need to redirect output if you do not want to log anything - If you did set up logging and wish to stream it in another tmux window, use
tail -f ~/Documents/cronAPI.log