go-project-template/README.md

33 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

# go-project-template
This is a template for go projects. It provides a postgres database connection and a webserver.
## Template Usage
This template is intended for use with [gonew](https://go.dev/blog/gonew), but can also be manually copied and the package name updated.
After you run gonew or update the package name manually, you will also want to:
2024-07-25 06:01:44 +00:00
* search for the string `go-project-template` and replace it with the name of your project, as that string appears in a few places other than the package name itself.
* Rename the sample config file in the root from `go-project-template.sample.json`
2024-07-25 06:01:44 +00:00
* You might want to put a human-readable project name in `httpserver/templates/base.html`, where `go-project-template` appears multiple times.
* Rewrite this README
## Project Usage
This project requires a postgres server. For development, it is usually easiest to create a temporary database in a container:
```bash
docker run --rm --name postgresql -e POSTGRES_PASSWORD=password -p 5432:5432 library/postgres
```
Then make a copy of the sample config file:
```bash
cp go-project-template.sample.json go-project-template.json
```
The database schema and migrations are defined in `db/migrations/`. Migrations are applied by [goose](https://github.com/pressly/goose) when the program starts.
Queries are written in `database/queries/`, which gets read by [sqlc](https://sqlc.dev) to generate much of the go code in `db/`. If you update a query, run
`sqlc generate` to update the generated go files.