A simpler way to setup infrastructure for your golang project!
here the module we provided for your project :
- Database (Postgre & Mongo) support multi instance
- Encryption (AES & Bcrypt)
- Identifier
- JSON Web Token
- SMTP With Template Processor
- Payment Gateway (Midtrans)
- Whatsapp (Twillio)
- Firebase
first add go-infrast package to your project, by using this command :
go get github.com/smokers10/go-infrast
here the example of configuration file you can follow :
application :
port: :8000
secret: your-encrypted-secret
user_management_pg_instance: user-management # which postgresql instance used for user management
postgres : [
{
label: general,
host: localhost,
port: 5432,
user: testuser,
password: testpass,
db_name: testdb,
max_open_connections: 1,
max_idle_connections: 2,
connection_max_life_time: 2,
},
{
label: user-management,
host: localhost,
port: 5433,
user: infrast_um,
password: infrastumpass,
db_name: infrastdbum,
max_open_connections: 1,
max_idle_connections: 2,
connection_max_life_time: 2,
},
]
mongodb : [
{
label : "dummy1",
uri : localhost/bla-bla-bla,
max_pool : 10,
min_pool : 5,
max_idle_connections : 2,
db_name : testdb,
},
{
label : "dummy2",
uri : localhost/bla-bla-bla,
max_pool : 10,
min_pool : 5,
max_idle_connections : 2,
db_name : testdb,
},
]
smtp:
host: localhost
password: your-encrypted-smtp-password
username: testuser
port: 5432
sender: sender
midtrans :
server_key: your-encrypted-midtrans-server-key
iris_key: your-encrypted-midtrans-iris-key
enabled_payments:
- bca-klik
- bri
- gopay
whatsapp :
sid: wa-sid
auth_token: encrypted-auth-token
sender: +628<...>
firebase:
service_account_key: your-encrypted-service-account-key
WARNING Some configuration value need to be encrypted such us:
- Application secret
- PostgreSQL password
- MongoDB URI
- SMTP password
- Midtrans server key
- Midtrans iris key
- Whatsapp auth token
- Firebase service account key
if you set mentioned config value with plain text it will give you error message, due to how we implement encryption on this package please use our provided tool enigma for creating confidential configuration value.
How To Setup Firebase
As you can see the firebase configuration required firebase service account key, to get key please follow this instruction
- Go to your firebase console then go to
project setting
. - Select
service account
tab. - On
firebase admin SDK
clickGenerate new private key
button, it will show you modal pop up clickGenerate Key
you will download a JSON file from firebase console. - After you downloaded the JSON, open the file and then encode all information inside using base64, you can use this site to encode your private key.
- encrypt your encoded private key using enigma.
- Set encrypted private key to your configuration YAML.
here the code example on how to use infrast with fiber framework:
package main
import (
"github.com/gofiber/fiber/v2"
infrast "github.com/smokers10/infrast/head"
)
func main() {
app := fiber.New()
key := os.GetEnv("aes-key-env-name")
infrast, err := infrast.Head("infrast_configuration.yaml", key)
if err != nil {
panic(err)
}
configuration := infrast.Configuration
app.Listen(configuration.Application.Port)
}
Note you can make your own AES key based on this documentation or use auto generated key by enigma
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch
- Commit your Changes
- Push to the Branch
- Open a Pull Request
The following packages were used in this project :
- golang jwt - Repository / Package Page
- goolang uuid - Repository / Package Page
- lib pq - Repository / Package Page
- nyaruka phonenumbers - Repository / Package Page
- stretchr testify - Repository / Package Page
- gotp - Repository / Package Page
- mongo driver - Repository / Package Page
- crypto - Repository / Package Page
- yaml - Repository / Package Page
- midtrans go - Repository / Package Page
- twillio go - Repository / Package Page
- firebase - Repository / Package Page
- and many more
Nadzar Mutaqin - instagram - linkedin - nadzarmutaqin4@gmail.com