# README
Go Web API Template
This repository is project template for Go Web API application.
Features
- Onion Architecture
- DI Container
- Server generation from swagger
- Validator
- ORM
- Logging
- Error Handling (Stack trace)
- Seeder
Requirements
Usage
cp .env.example .env
cp .env.feature.example .env.feature
go generate -x ./...
docker compose up -d
DB Migration and Seeding
docker compose exec app sh
go run commands/migrate/main.go
go run commands/seed/main.go
Generate Server
swagger generate server -A App -f ./swagger.yml --model-package=restapi/models
Confirm
curl -i "http://localhost:34567"
curl -i "http://localhost:34567/companies"
curl -i "http://localhost:34567/todos"
curl -i "http://localhost:34567" -d "{\"description\":\"message $RANDOM\"}" -H 'Content-Type: application/io.goswagger.examples.todo-list.v1+json'
curl -i localhost:34567/1 -X DELETE -H 'Content-Type: application/io.goswagger.examples.todo-list.v1+json'
Tests
Unit test
go test ./...
Feature test
https://localhost:8080 に接続し、example_test
データベースを作成してから以下のコマンドを実行する
docker compose exec app sh
DB_DATABASE=example_test go run commands/migrate/main.go
gotestsum --hide-summary=skipped -- -tags feature ./...
Setting remote debug on GoLand
https://gist.github.com/t-kuni/1ecec9d185aac837457ad9e583af53fb#golnad%E3%81%AE%E8%A8%AD%E5%AE%9A
See Database
See SQL Log
docker compose exec db tail -f /tmp/query.log
Create Scheme
go run entgo.io/ent/cmd/ent init [EntityName]
Build Container for production
docker build --target prod --tag go-web-api-template .
タスク
- polluterからtestfixturesに載せ替え
- マイグレーションの管理を切り出し
- 認証処理のモック化
- レスポンスがJSONではない処理のテスト(例えばファイルのダウンロードなど)
- 現在日時のモック化
- DB接続のタイムゾーン
- 本番環境用コンテナ
- vscode用devcontainer定義
- coreファイルが残る問題
- コンテナ上で生成したファイルのオーナーがrootな問題
- アクセスログミドルウェア
- OpenAPIと連携
- make コマンドでコード生成できるようにする(+ファイルのクリーンアップ)
- 既存の仕組みと統合する
- airに対応
- DB接続に対応
- テストに対応
- [-] 共通エラーハンドラ対応
- バリデーションを試す
- テストをmakeコマンドから実行できるようにする
- テストのカバレッジの可視化
- テストの前処理、後処理をリファクタ(txdbの初期化処理タイミングを変更)
- テストのレコードの初期投入を見やすくする
- CI
- CD
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author