The following procedure is intended to help you quickly customize this starter kit for your unique application.
- Clone the starter kit.
- Delete the local
.git
directory. - Ensure you can successfully run the app for local development and test coverage. See the Development section of the README for further instructions.
- Choose a unique service port for the HTTP server to avoid collisions with other service port bindings on the host machine. Replace
9000
with your unique service port in the following files:
/config/config.toml
/docker-compose.yml
/Dockerfile
/test/Dockerfile
- Choose a unique service port for the PostgreSQL server. In the
/docker-compose.yml
file, replace the port mapping25432:5432
with{custom-postgres-port}:5432
. - Choose a unique service port for the Redis server. In the
/docker-compose.yml
file, replace the port mapping26379:6379
with{custom-redis-port}:6379
. Alternatively, just remove theredis
service and theapi.depends_on.redis
configuration.
- Choose a name for the app. This will be referred to as
{appname}
in the rest of this guide. - Update the go module file and all import paths:
- Find all occurrences of
github.com/BetterWorks/go-starter-kit
and replace withgithub.com/BetterWorks/{appname}
- Delete
/go.sum
- Run
go mod tidy && go mod vendor
- Update the
/package.json
name
field to{appname}
. - Update the
/justfile
project
field to{appname}
.
At this point, check that the app is still in a working state by rebuilding and rerunning the docker service containers:
$ docker compose down
$ docker compose build --no-cache
$ docker compose run --rm --service-ports api
❗ Please familiarize yourself with the Application Design & Architecture before proceeding with Code Changes and Migrations.
The starter kit contains a single generic resource called Resource
. You can use this type as a reference when creating the resources for the app, and then delete this generic code later.
By example, let's say we're adding a new resource called TShirt
.
The following is a list of locations where code needs to be modified to add the new resource/model:
- add
/internal/core/models/tshirt.go
containing the various type definitions - modify
/internal/core/interfaces/repo.go
to add:type TShirtRepository interface { ... }
definition
- add
/internal/repo/tshirt.go
repository code - add
/internal/domain/tshirt.go
service code - modify
/internal/domain/application.go
to add:TShirtService interfaces.Service
to theServices
struct
- add
/internal/http/routes/tshirt.go
withTShirtRouter
route definitions - modify
/internal/http/httpserver/router.go
to add:TShirtController *controllers.Controller
to thecontrollerRegistry
structTShirtController: ...
to thecontrollerRegistry
in theregisterControllers
functionroutes.TShirtRouter(app, c.TShirtController, ns)
to theregisterRoutes
method
- modify
/internal/resolver/loaders.go
to add:- a
TShirtRepository
method mirroring theExampleRepository
method - a
TShirtService
method mirroring theExampleService
method - an
TShirt: r.TShirtService(),
entry in theDomain
method'sdomain.Services
struct
- a
- modify
/internal/resolver/resolver.go
to add:TShirtRepo interfaces.TShirtRepository
to theConfig
structtShirtRepo interfaces.TShirtRepository
to theResolver
structtShirtRepo: c.TShirtRepository,
to theResolver
instantiation in theNewResolver
functionTShirtService interfaces.Service
to theConfig
structtShirtService interfaces.Service
to theResolver
structtShirtService: c.TShirtService,
to theResolver
instantiation in theNewResolver
function
Resource
code can be removed, and the app code developed from there.
❗ Please note that these patterns are just a beginning. Codebases with higher complexity require more than what is demonstrated here with a simple, generic use case.
The existing migrations work for the Resource
type. It may be advantageous to simply add new migrations for the new resources, and then circle back with a clean initial-schema
migration once the app is in a stable state.
To create a new set of initial migrations:
- delete the existing set of
/database/migrations/*.sql
files - use the commands described in the Migrations section of the README.
Run git init
and go build cool stuff!