Deploy Go API to Render
In this lesson, we'll deploy our Go API to Render. Render is a really helpful service that takes away a lot of the complexity of deploying and infrastructure. We will configure a service that builds a Go application, and runs it.
For this tutorial, we are assuming you have a Render account.
Create a New Repository
We will create a new Github repository (You can use Gitlab too). This is where we store our code, and where Render pulls from.
The next set of steps is creating a basic Go API. If you already have one, you can skip to the next section.
Clone your repository to your Go workspace. For me, it’s
We are going to initialise a new module.
We will add
main.go to the root.
We will start it up with:
We have a basic Go script running, time to add an basic endpoint. We will be using Gin. Run this command to install the module:
We will update our
main.go file to have an endpoint and router.
Once again, run it with:
You can verify everything is setup by navigating to
[http://localhost:8080](http://localhost:8080) in your browser.
You may want to add a
.gitignore . Otherwise, push everything to your remote repository.
Create a new Service
Sign into your Render account. In the navigation bar, hit “New”, then select “Web Service”. We want our service to be exposed to the public internet.
Navigate to the repository you want to connect, and hit the “Connect” button in line.
You will provide details about the service. For the name, make it something recognisable for you. The region should be close to your customers, or aligns with your other services (if you have them). I’m going to stick with “Oregon (US West)”. For me, it’s detected the Runtime is “Go”. For the build command, I usually test it out. On your local machine:
This builds an executable of your code. Then run it with:
You should see your API running. If this wasn’t successful on your local, it will definitely fail remotely.
Select your size, then hit “Create Web Service”.
The service will build for the first time. Give it a few minutes. We will then navigate to the Render URL provided to confirm we can access it.
In the logs, you should see the same print out as your local machine.
For ports, you can see it determine what port. You can also set it under advance.
You can see it’s loading our health endpoint. That’s it! You are all setup on Render. Every time you merge to
main , it will redeploy all changes. You can configure a custom URL under “Settings”.
Thanks for reading!