GO REST App
This guide deploys a Golang REST application to ComputeSphere.
We use a pre-built ComputeSphere container image in this guide.
Prerequisites
- A ComputeSphere account.
- Docker and Docker registry repository - If using your own Docker image.
- ComputeSphere API Token - Follow the steps here to get your account API token.
Step 1: Setting Up the Project
Use a Pre-built Image
You can use our pre-built Docker image on the ComputeSphere registry. Here's the image tag that we'll use.
quay.io/computesphere/computesphere-golang-rest-api-example:latest
Use Your Docker Image
These steps guide you in creating an image based on our project example.
- Clone the project example:
git clone https://github.com/computesphere-samples/computesphere-golang-rest-api-example.git
- Create the Docker image:
docker build -t computesphere-golang-rest-api-example:v0.0.1 .
- Tag and Push the Docker image:
docker tag computesphere-golang-rest-api-example:v0.0.1 [REPOSITORY]/computesphere-golang-rest-api-example:v0.0.1
docker push [REPOSITORY]/computesphere-golang-rest-api-example:v0.0.1
Replace [REPOSITORY] with the name of your image registry repository.
Step 2: Create a Project
- Login to your ComputeSphere console → click on New Project.

- Provide a name for the project, then click Create.

Step 3: Create a new service
- Inside your project page, click New Service.

- Click New App Service.

- Click Deploy Image.

Step 4: Configure and Deploy the Service
- Provide a name for the service and click Next.

- In the dropdown, click Create New Environment. In this section, you can add application environment variables, such as General Variables or Secret Variables. The variables are key-value pairs.
For more information regarding Environment, please see here.

- Provide the name and the region for the environment → click Create → click Next.

- Put the ComputeSphere pre-built image link:
quay.io/computesphere/computesphere-golang-rest-api-example:latest.
If you have your own docker container image, change the URL to your image URL.

- Select the number of Spherelets to allocate. In this example, we're going to use 4 Spherelets.

- You can choose to add storage to your service. In this example, we won't use one.

- You can enable health checks by setting the configurations. For this example, we'll keep the default settings.
For more information regarding Health Checks, please see here.

- Specify the port → click Deploy. For this example, we use the 8000 port. Select the Public Access for network access.
For more information regarding Networking, please see here.

- Wait for the deployment to finish → new screen appears with details about your deployed application. Click Open Website.

- If you see the following page, your deployment was successful.

- Append
/pingto the URL to see the response from the Go application.

Step 5: Accessing the API
Replace [BASE_URL] with the URL of your deployed application.
- Create an article:
curl -L 'https://[BASE_URL]/api/v1/articles' \
-H 'Content-Type: application/json' \
-d '{
"title": "First article",
"desc": "My first article in Golang application",
"content": "Here goes my extraordinary story....",
"coverImageUrl": "https://some.url/images/adsflkj4"
}'
- Get all articles:
curl -L 'http://localhost:8000/api/v1/articles'
- Retrieve a specific article:
curl -L 'https://[BASE_URL]/api/v1/articles/1'
- Update an article:
curl -L -X PUT 'https://[BASE_URL]/api/v1/articles/1' \
-H 'Content-Type: application/json' \
-d '{
"id": 1,
"title": "First article - updated",
"desc": "My first article in Golang application",
"content": "Here goes my extraordinary story....",
"coverImageUrl": "https://some.url/images/adsflkj4"
}'
- Delete an article:
curl -L -X DELETE 'https://[BASE_URL]/api/v1/articles/1'
That's it. Now, you have successfully deployed your application to ComputeSphere.