The go-starter-kit is a starter kit for Go projects that enables you to easily kickstart your Golang project. This project comes pre-configured with MySQL support and provides the necessary tools to streamline your development process.
Developed by Ayman Elmalah. You can find more of Ayman's work on GitHub.
To install and get started with the go-starter-kit, follow these steps:
- Clone the repository:
git clone https://github.com/ayman-elmalah/go-starter-kit
Change to the project directory:
cd go-starter-kit
Before you start using the go-starter-kit, make sure you have the following prerequisites installed:
- CompileDaemon: A tool to watch and rebuild your Go application on changes. Install it using the following command:
go install -mod=mod github.com/githubnemo/CompileDaemon
- golang-migrate: A tool to manage database migrations in your Go project. Follow the installation guide here to install it.
Then run the following command to tidy up your Go modules:
go mod tidy
Copy the example configuration file:
cp config/config.yaml.example config/config.yaml
Open the config/config.yaml
file and provide your data and database credentials.
To start the project, use the following command:
CompileDaemon -build="go build -o main main.go" -command="./main serve"
This command uses CompileDaemon to automatically build and restart your Go application whenever changes are detected.
Follow these steps to create and manage database migrations:
To create a new migration, run the following command:
migrate create -ext sql -dir db/migrations -seq create_users_table
To apply migrations, use the following commands:
- Migrate Up:
go run main.go migrate-up
- Migrate Down
go run main.go migrate-down
For more advanced migration features and options, refer to the golang-migrate guide.
To add a new module to the project, follow these steps:
-
Create a new directory within
internal/modules
for your new module. You can name it based on the module's functionality. -
Inside the newly created module directory, set up the following structure:
- Create a
routes
directory. - Create a
controllers
directory. - Optionally, create additional directories like
services
andrepositories
as needed for your module's architecture.
- Create a
-
Within the
routes
directory, create aroutes.go
file. You can model this after the structure in/internal/modules/home/routes/routes.go
. -
Similarly, within the
controllers
directory, create a controller file, for examplemodule_controller.go
. You can follow the structure of/internal/modules/home/controllers/home_controller.go
as an example. -
After setting up routes and controllers, add the route(s) defined in your module's
routes/routes.go
to the global router. You can do this by including the route(s) in/internal/providers/routes/route.go
.
By following these steps, you'll be able to integrate new modules into your project, each with its own set of routes, controllers, and other components. This modular approach helps keep your project organized and maintainable.