This is the source code for the backend development of the No Stunting App.
The API Documentation for deployed backend system can be seen in
This documentation is divided into three sections, including:
After cloning this repository, you can follow several steps, including:
Installing Golang is quite easy, it can be done in several steps, including:
- Download Golang Install in this link.
- Click Install
- Proceed as the installation in general.
This project use MongoDB as Database Management System, and use MongoDB Atlas as DBMS Environment. You can setup the MongoDB Atlas by several steps, but make sure you have account in MongoDB Atlas (It is free), if you don't have account, easily you can register here.
After you have an account, you can follow the next step, including:
-
Create Cluster
Choose Cluster do you want and the specification, here for example, you can choose M0 with free payment, Google Cloud Provider, choose the Region and define the Cluster Name. and Click Create.
-
Create Database Account
After creating cluster, you need to create user for read and write for any data in your project.
my_username can be replaced with your own username
my_password can be replaced with your own password
-
Add IP Access List
To allow IP that is connected to database, you can add IP. Here we using
0.0.0.0/0
for allowing all of connection from all IP. Easily click Add Entry -
Get Connection String
When you already setup your database, you will be redirected to Database Deployment, here, you can click Connect button.
Choose Connect your application, and will appear modal box a modal box will appear more or less like this.
Copy the connection string and replace blue sensored text with your username and
<password>
with password you entered before.
Dependencies for projects is an important things, you need to install to your currenct project, simply, in Go we just only :
- Change your active directory to your cloned directory
- Write command
go get
Navigate active directory to your project directory, and you may continue... :)
If you see env.example
in this repository, it is the example ENV file that will be loaded in the runtime. So, the next steps is:
-
Copy
env.example
file to the same directory and give name.env
. -
Open the file, and you will see code like this:
MONGOURI="YOUR_MONGODB_URI"
-
Replace "YOUR_MONGODB_URI" with Connection String you created before.
MONGOURI=mongodb+srv://<username>:<password>@<clustername>.t46b00s.mongodb.net/?retryWrites=true&w=majority
-
Save the file
To check and make sure the setup is already done, we need to check with trying to run the system, so let us do it! :D
Stay in project directory, run command go run index.go
If the last line of the terminal output is:
[GIN-debug] Listening and serving HTTP on :8080
The code is already setup and successfully running. :)
We need to deploy a system for the benefit of flexible access, here we use Google Cloud with it's Cloud Run, before those, you need to upload your setup project to your own Github.
-
Create Service
In Cloud Run Main Panel, simply click Create Service
-
Setup Cloud Build, Sservice name, region, CPU Allocation and Autoscalling
By Clicking SET UP WITH CLOUD BUILD, will appear side section Set Up Cloud Build.
Before this, you have already deploy your repository in your Github.
If you are new in Google Cloud, you have to configure connection between your Github with Google Cloud.
Simply click Save
-
Authentication
-
Setup Environment Variable
Expand Collapsable Container, Networking, Security, in Section Environment variable, you can input your MONGODB Connection String like picture below:
-
Click CREATE