Refactor for use with Cookiecutter

Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
akp 2022-10-02 21:26:54 +01:00
parent d78975a540
commit 5f7c2f42ec
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
18 changed files with 41 additions and 21 deletions

View file

@ -1,15 +1,15 @@
# go-fiber-sql
# cookiecutter-go-web-app
A project template for a web application based on the Fiber web framework. This incorporates:
A project template for a web application written in Go based on the [Fiber](https://github.com/gofiber/fiber) web framework. This incorporates:
* Error handling with `github.com/rs/zerlog` and `github.com/pkg/errors`
* Database migrations (requires Go v1.18 or newer)
* Database migrations
* Tools to load YAML-based configurations
## To use this template:
To use this template, you must have [Cookiecutter](https://github.com/cookiecutter/cookiecutter) installed.
* Add a `LICENSE`
* Update the package name in `go.mod` and in the imports within the application
* Rename the `application` directory to your application's name
* Define your database DSN and driver
* Write some code and make an app, I guess?
```
python3 -m pip install --user --upgrade cookiecutter
cookiecutter https://github.com/codemicro/cookiecutter-go-web-app.git
```

12
cookiecutter.json Normal file
View file

@ -0,0 +1,12 @@
{
"projectName": "Hello World",
"projectDescription": "This is a web application that says hello world.",
"projectSlug": "helloWorld",
"mainPackageName": "{{ cookiecutter.projectSlug }}",
"modulePath": "github.com/codemicro/{{ cookiecutter.projectSlug }}",
"minimumGoVersion": "1.19",
"__mainPackagePath": "{{ cookiecutter.modulePath }}/{{ cookiecutter.mainPackageName }}"
}

View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
go fmt ./... > /dev/null

View file

@ -0,0 +1,5 @@
# {{ cookiecutter.projectName }}
*{{ cookiecutter.projectDescription }}*
---

View file

@ -1,6 +1,6 @@
module github.com/codemicro/go-fiber-sql
module {{ cookiecutter.modulePath }}
go 1.18
go {{ cookiecutter.minimumGoVersion }}
require (
github.com/gofiber/fiber/v2 v2.35.0

View file

@ -3,7 +3,6 @@ package db
import (
"context"
"database/sql"
"github.com/codemicro/go-fiber-sql/application/config"
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
@ -11,6 +10,7 @@ import (
"github.com/uptrace/bun/dialect/sqlitedialect"
"github.com/uptrace/bun/extra/bundebug"
"time"
"{{cookiecutter.__mainPackagePath}}/config"
)
type DB struct {

View file

@ -3,11 +3,11 @@ package db
import (
"context"
_ "embed"
"github.com/codemicro/go-fiber-sql/application/db/migrations"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/uptrace/bun/migrate"
"time"
"{{cookiecutter.__mainPackagePath}}/db/migrations"
)
func (db *DB) Migrate() error {

View file

@ -2,9 +2,9 @@ package migrations
import (
"context"
"github.com/codemicro/go-fiber-sql/application/db/models"
"github.com/pkg/errors"
"github.com/uptrace/bun"
"{{cookiecutter.__mainPackagePath}}/db/models"
)
func init() {

View file

@ -1,12 +1,12 @@
package endpoints
import (
"github.com/codemicro/go-fiber-sql/application/config"
"github.com/codemicro/go-fiber-sql/application/db"
"github.com/codemicro/go-fiber-sql/application/paths"
"github.com/codemicro/go-fiber-sql/application/util"
"github.com/gofiber/fiber/v2"
"time"
"{{cookiecutter.__mainPackagePath}}/config"
"{{cookiecutter.__mainPackagePath}}/db"
"{{cookiecutter.__mainPackagePath}}/paths"
"{{cookiecutter.__mainPackagePath}}/util"
)
type Endpoints struct {

View file

@ -2,15 +2,15 @@ package main
import (
"fmt"
"github.com/codemicro/go-fiber-sql/application/config"
"github.com/codemicro/go-fiber-sql/application/db"
"github.com/codemicro/go-fiber-sql/application/endpoints"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"os"
"os/signal"
"strconv"
"syscall"
"{{cookiecutter.__mainPackagePath}}/config"
"{{cookiecutter.__mainPackagePath}}/db"
"{{cookiecutter.__mainPackagePath}}/endpoints"
)
func run() error {