{"id":24929802,"url":"https://github.com/traptitech/game3-back","last_synced_at":"2025-03-28T13:28:57.792Z","repository":{"id":212100817,"uuid":"729920750","full_name":"traPtitech/game3-back","owner":"traPtitech","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-06T21:24:08.000Z","size":208,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T13:51:52.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/traPtitech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-10T18:54:03.000Z","updated_at":"2025-01-06T21:24:13.000Z","dependencies_parsed_at":"2023-12-12T15:31:05.928Z","dependency_job_id":"78010fbf-fc39-4482-bddf-e884a2e18eca","html_url":"https://github.com/traPtitech/game3-back","commit_stats":null,"previous_names":["traptitech/game3-back"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traPtitech%2Fgame3-back","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traPtitech%2Fgame3-back/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traPtitech%2Fgame3-back/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traPtitech%2Fgame3-back/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traPtitech","download_url":"https://codeload.github.com/traPtitech/game3-back/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246036827,"owners_count":20713300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-02T13:51:54.773Z","updated_at":"2025-03-28T13:28:57.746Z","avatar_url":"https://github.com/traPtitech.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/traPtitech/game3-front/blob/main/public/favicon.svg\" align=\"right\" width=\"250\" alt=\"game3 logo\"/\u003e\n\n# game3-back\n\n[Game³](https://game3.trap.games)のバックエンドです。\n\nフロントエンド: \u003chttps://github.com/traPtitech/game3-front\u003e\n\n[Go](https://github.com/golang/go)のフレームワーク[Echo](https://github.com/labstack/echo)を使用して作成しています。\n\n## ドキュメント\n- [OpenAPI](https://github.com/traPtitech/game3-back/blob/main/docs/openapi.yaml): APIの定義\n- [DB Schema](https://github.com/traPtitech/game3-back/blob/main/docs/db_schema.mmd): データベースの定義\n\n## 開発環境の実行\n- [Docker](https://www.docker.com/)と[Docker Compose(ver2.22以上)](https://docs.docker.com/compose/)が必要です。\n- `docker compose watch`でアプリが起動し、以下にアクセスできます。\n  - \u003chttp://localhost:8080/api/ping\u003e (API)\n  - \u003chttp://localhost:8081/\u003e (Adminer: DBの管理画面)\n- 認証部分を動かすためには`.env`ファイルで環境変数を定義する必要があります。\n  - \u003chttps://ns.trap.jp/apps/0765eb937f27fdc377eec1/settings/envVars\u003e を参考に、\n  - ```\n    DISCORD_CLIENT_ID=NeoShowcaseと同じ\n    DISCORD_CLIENT_SECRET=NeoShowcaseと同じ\n    DISCORD_CLIENT_REDIRECT_URI=\"http://localhost:8080/api/auth/callback\"\n    DISCORD_SERVER_ID=NeoShowcaseと同じ\n    DISCORD_BOT_TOKEN=NeoShowcaseと同じ\n    DISCORD_NORMAL_PARTICIPANT_ROLE_ID=NeoShowcaseと同じ\n    DISCORD_EXHIBITOR_PARTICIPANT_ROLE_ID=NeoShowcaseと同じ\n    ``` \n    を`.env`に記載すると正常に全てが動作します。\n\n## 構成\n**TL;DR**: 大体`main.go`→`internal/handler`(ルーティング)→`internal/repository`(DBの操作)\n- https://github.com/ras0q/go-backend-template をベースに作成。\n- `main.go`: エントリーポイント\n  - 依存ライブラリの初期化など最低限の処理のみを書く\n  - ルーティングの設定は`./internal/handler/handler.go`に書く\n  - 肥大化しそうなら`./internal/infrastructure/{pkgname}`を作って外部ライブラリの初期化処理を書くのもアリ\n- `internal/`: アプリ本体の主実装\n  - Tips: Goの仕様で`internal`パッケージは他プロジェクトから参照できない (\u003chttps://go.dev/doc/go1.4#internalpackages\u003e)\n  - `api/`: 外部APIのラッパー\n    - 外部サービス（例：Discord API）へのリクエストを抽象化したメソッドを提供します。\n  - `domain/``: ドメインモデル\n    - アプリケーションのビジネスロジックをカプセル化したドメインオブジェクトを定義します。\n    - 今回は、ほとんどoapi-codegenが生成したmodelを使っているので、出番は少しだけ。\n  - `handler/`: ルーティング\n    - 飛んできたリクエストを裁いてレスポンスを生成する\n    - DBアクセスは`repository/`で実装したメソッドを呼び出す\n    - Tips: リクエストのバリデーションがしたい場合は↓のどちらかを使うと良い\n      - [go-playground/validator](https://github.com/go-playground/validator)でタグベースのバリデーションをする\n      - [go-ozzo/ozzo-validation](https://github.com/go-ozzo/ozzo-validation)でコードベースのバリデーションをする\n  - `migration/`: DBマイグレーション\n    - DBのスキーマを定義する\n    - Tips: マイグレーションツールは[pressly/goose](https://github.com/pressly/goose)を使っている\n      - 例: `cd internal/migration \u0026\u0026 goose mysql \"root:pass@tcp(172.26.0.2)/app?parseTime=true\" status`\n    - 初期化スキーマは`1_schema.sql`に記述し、運用開始後のスキーマ定義変更等は`2_add_user_age.sql`のように連番を振って記述する\n      - Tips: Goでは1.16から[embed](https://pkg.go.dev/embed)パッケージを使ってバイナリにファイルを文字列として埋め込むことができる\n  - `repository/`: DBアクセス\n    - DBへのアクセス処理\n      - 引数のバリデーションは`handler/`に任せる\n  - `pkg/`: 汎用パッケージ\n    - 複数パッケージから使いまわせるようにする\n    - 例: `pkg/config/`: アプリ・DBの設定\n    - Tips: 外部にパッケージを公開したい場合は`internal/`の外に出しても良い\n    - 定数やenumや使いまわす関数をここで定義している。\n- `openapi/`: oapi-codegenがopenapi.yamlから生成したモデルとサーバー\n  - https://github.com/deepmap/oapi-codegen を用いて、OpenAPIの定義からGoのコードを生成している。以下のコードで生成できる。\n  - ```\n    cd docs\n    oapi-codegen --config=models.cfg.yaml openapi.yaml\n    oapi-codegen --config=server.cfg.yaml openapi.yaml\n    ```\n- `integration/`: 結合テスト\n  - 現状テストを書いていないので、使っていない。//TODO\n  - `internal/`の実装から実際にデータが取得できるかテストする\n  - DBの立ち上げには[ory/dockertest](https://github.com/ory/dockertest)を使っている\n  - 短期開発段階では時間があれば書く程度で良い\n  - Tips: 外部サービス(traQ, Twitterなど)へのアクセスが発生する場合は[golang/mock](https://github.com/golang/mock)などを使ってモック(テスト用処理)を作ると良い\n\n## 長期開発に向けた改善点\n- 単体テスト・結合テストのカバレッジを上げる\n  - カバレッジの可視化には[Codecov](https://codecov.io)(traPだと主流)や[Coveralls](https://coveralls.io)が便利\n- ログの出力を整備する\n  - ロギングライブラリは好みに合ったものを使うと良い\n\n## TODO\n- テストを書く\n- DBの中に保存している画像を、オブジェクトストレージに移行する。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraptitech%2Fgame3-back","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraptitech%2Fgame3-back","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraptitech%2Fgame3-back/lists"}