doc.dev1x.org

アプリケーションアーキテクチャ設計に関する覚書(Go)

1. 前提条件

2. 基本的な考え方

3. プロジェクト構造

4. src以下の構造

ディレクトリ構造

src/
├─ config/
├─ handler/
├─ lib/
├─ mock/
├─ model/
├─ repository/
├─ usecase/
├─ validator/
└─ main.go

config

package config

type Config struct {
    ...
}

handler

lib

mock

model

repository

usecase

type ShowExampleList interface {
    Execute() error
}

type showExampleList struct {
    ...
}

func (u *showExampleList) Execute() error {
    ...
}
type Usecases interface {
    ShowExampleList()   ShowExampleList
    ShowExampleDetail() ShowExampleDetail
}

type usecases struct {
    ...
}

func NewUsecases() Usecases {
    return &usecases{}
}

func (u *usecases) ShowExampleList() ShowExampleList {
    return &showExampleList{}
}

func (u *usecases) ShowExampleDetail() ShowExampleDetail {
    return &ShowExampleDetail{}
}

validator

main.go

5. ファクトリーとinterface

packcage

6. 各レイヤーのユニットテスト

repository