GoGetter is a collection of reusable Go modules, pre-configured to work with Uber's Fx Framework. The aim is to provide a way to rapidly spin up service(s) using pre-built modules. This repository also includes a CLI tool to streamline common development tasks.
All modules are dependent on:
Modules
- Configuration Management
- Logging
- HTTPServer
- JWT
- Database Integration using GORM
- Mailer
Per Module Documentation
COMING SOON!
Usage
To use the modules in your project, simply import them from main, set up the configurations, and initiate them in your Fx App.
Refer to example.go for a working example.
Configuration
There are 3 levels of configuration, listed in order of precedence:
- Environmental variables:
- Config Files
- Format:
scope.key
- Separator:
.
- Refer to the config.yaml for an example.
- Fallback Config
- Format:
scope.key
- Separator:
.
- Refer to the example.go file for an example.
Injection
Refer to example.go for a working example.
CLI
The CLI tool, built with Cobra, is a convenient way to spin up an entire service in one go.
Usage
To use the CLI tool, install it first:
go install github.com/alsey89/gogetter/cmd/gogetter@latest
Commands
Init
Init initializes the project. It sets up go module, creates a main.go file and installs the relevant dependencies. Optionally, it can set up a Dockerfile, a docker-compose.yaml, and git.
gogetter init
Here's an example of the process:
? Welcome to the GoGetter CLI. This will begin the setup process for your new Go service. Continue? Yes
? Enter the go module name for your project. [Example: github.com/alsey89/gogetter] test
? Enter the directory for your project. Service will be initiated at the current directory if left empty.
? Do you want to include a Echo-JWT middleware module? Yes
? Do you want to include a GORM Postgres database connector module? Yes
? Do you want to include a GoMail mailer module? Yes
? Do you want to set up git for the project? Yes
? Do you want to set up Dockerfile for the project? Note: if no is selected, docker-compose setup will be skipped Yes
? Do you want a docker-compose setup for local development? This will set up a docker-compose file for a local postgres and server with volume mapping. You can add the frontend yourself if you want. Yes
Run
Run spins up the docker-compose service, defaulting to a dev setup with automatic rebuild and reload.
gogetter run dev
Arguments:
- dev: sets BUILD_ENV=development
- development: sets BUILD_ENV=development
- prod: sets BUILD_ENV=production
- production: sets BUILD_ENV=production
Effects:
Check the Dockerfile template to see how the BUILD_ENV affects the container setup.
Stop/Down
Stop/Down spins down running docker-compose service and removes orphans.
gogetter stop
OR
gogetter down
Troubleshooting
If the command is not found after installation, check Go Environmental variables and system $PATH.
Contribution
Contributions are welcome! Please fork the repository and submit pull requests with your proposed changes. For major changes, please open an issue first to discuss what you would like to change.
Ensure to update tests as appropriate.
License
This project is licensed under the MIT License - see the LICENSE file for details.