Create a travel list app with Go, Fiber, Angular, MongoDB and Google Cloud Secret Manager
I have been writing app service/REST/RPC in Go on and off quite awhile, for freelancing and side projects. I have use numbers of frameworks/libraries like Echo, Gorilla toolkit and so on. Unfortunately, I did not use Go at work. Go is not popular in my region. I write web and Express Node.js at work. Recently I discovered Fiber, a new framework inspired by Express
The tech stack will be
- Go (Fiber)
- MongoDB (MongoDB Atlas)
- Angular (Not the main focus here, could be any web framework)
- Google Cloud
The source code is available at Github. The code is written with Clean Architecture pattern. API and static web are served together with Fiber. This approach might not suitable for your use case, but it fits well for this mini travel list app as it can bundle together as one service.
Feel free to create PR if you have any interesting features to add. I will try to keep this repo minimum. Ultimately this repo serves as
template repo to get started
Live preview at travel.yongweilun.me
Updated: Live preview server was removed
- Setup MongoDB Atlas, more info on how to setup can find it developer.mongodb.com (optional if just to run locally)
- Setup Google Cloud project (optional if just to run locally)
1. Clone project source code
The source code is too long to paste here. Kindly refer to the repo at Github.
After you created cluster on MongoDB Atlas, you should able to get the connection string. Remember to add
DATABASE_URI: mongodb+srv://USERNAME:PASSWORD@CLUSTER/DATABASE?retryWrites=true&w=majority DATABASE_NAME: travels TRAVEL_COLLECTION: travel-list
3. Setup Secret Manager
This section can be skipped if you just want to run locally. This is important as I noticed a lot of engineers didn't handle secrets like database credentials correctly. Learn how to setup from cloud.google.com. The idea is to consume secrets from Secret Manager when
APP_ENV is production, to avoid any additional charges, the price of Secret Manager is relatively cheap though. Pricing list can be found here. But you can always consume secrets from Secret Manager and skip the
.env.yaml setup, depends on use case.
To create new secret, open console.cloud.google.com, navigate to
Security -> Secret Manager.
The secret value should be the value from
.env.yaml as shown in example below
After that, create service account, grant with
Secret Manager Secret Accessor role, save as
secret.json and put at
credentials/secret.json. Refer to cloud.google.com for more details.
Copy the Resource ID from Console, and set as environmental variable
4. Run the project
cd travel-list make install make start
Open browser at
This app will be used as the foundation of my Google Cloud series. In the coming sections, I will use this app and setup deployment to Cloud Run/GKE with CI/CD.