Giter Club home page Giter Club logo

dmm-go's Introduction

<<<<<<< HEAD

yatter-backend-go

Table of Contents

Development Environment

開発環境をdocker-composeで構築しています。

Requirements

  • Go
  • docker / docker-compose

Start

docker compose up -d

Shutdown

docker compose down

Log

# ログの確認
docker compose logs

# ストリーミング
docker compose logs -f

# webサーバonly
docker compose logs web
docker compose logs -f web

Hot Reload

airによるホットリロードをサポートしており、コードを編集・保存すると自動で反映されます。 読み込まれない場合はdocker compose restartを実行してください。

Swagger UI

API仕様をSwagger UIで確認できます。

開発環境を立ち上げ、Webブラウザでlocalhost:8081にアクセスしてください。

Test

各API定義の"Try it out"からAPIの動作確認を行うことができます。

Authentication

鍵マークのついたエンドポイントは認証付きエンドポイントです。

AuthenticationというHTTPヘッダにusername ${ユーザー名}を指定する単純な仕様です。

動作確認の際には画面上部の"Authorize"からヘッダの値の設定を行ってください。

DB

マイグレーションツールの用意はありません。

初回起動時にddl/以下にあるSQLファイルが実行されます。 再読み込みの際は.data/mysql/を削除し、DBを初期化してください。

docker compose down  # 開発環境が稼働中なら止める
rm -rfd .data/mysql  # `.data/mysql/`以下を削除
docker compose up -d # 再起動

Code

Architecture

.
├── app      ----> application core codes
│   ├── config   ----> config
│   ├── domain   ----> domain layer, core business logics
│   ├── handler  ----> (interface layer & application layer), request handlers
│   └── dao      ----> (infrastructure layer), implementation of domain/repository
│
└── ddl      ----> DB definition master

config

サーバーの設定をまとめたパッケージです。DBやlistenするポートなどの設定を取得するAPIがまとめてあります。

domain

アプリケーションのモデルを扱うdomain層のパッケージです。

domain/object

ドメインに登場するデータ・モノの表現やその振る舞いを記述するパッケージです。 今回は簡単のためDTOの役割も兼ねています。

domain/repository

domain/objectで扱うEntityの永続化に関する処理を抽象化し、インターフェースとして定義するパッケージです。 具体的な実装はdaoパッケージで行います。

handler

HTTPリクエストのハンドラを実装するパッケージです。 リクエストからパラメータを読み取り、エンドポイントに応じた処理を行ってレスポンスを返します。 機能の提供のために必要になる各種処理の実装は別のパッケージに切り分け、handlerは入出力に注力するケースも多いですが、今回は簡単のため統合しています。

dao

domain/repositoryに対する実装を提供するパッケージです。 DBなど外部モジュールへアクセスし、データの保存・取得・更新などの処理を実装します。

Module Dependency

モジュールの依存関係

Library

Utilities

このテンプレートでは実装をサポートするユーティリティ関数を提供しています。

app/handler/auth

認証付きエンドポイントの実装のためのミドルウェア関数を提供しています。 chi.Mux#Usechi.Mux#Withを用いて利用できます。

ミドルウェアを埋め込んだエンドポイントでは*http.RequestからAccountOfでリクエストと紐づくアカウントを取得できます。

// var r *http.Request
account := auth.AccountOf(r)

=======

dmm-go

origin/main

dmm-go's People

Contributors

taisei25864 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.