外部サービスから取得したデータを用いて 記事を作成し, 提供するAPIを Clean Architecture で実装した例.
News API で Developer Plan で APIトークンを取得し, .env
にトークンを記述して使用する必要がある.
NEWS_API_TOKEN={your api token}
This Application is open-sourced software licensed under the MIT
- NewsAPI Developer Plan( Powered by NewsAPI.org )
今回の実装では, クリーンアーキテクチャの4層は以下のようになった.
- Entity層:
entities
- Service層:
services
- Adapter層 :
adapters
- Repository層:
repositories
また, TopicsAPI
の実装に要した作成ファイルは以下の通り.
.
|
├── adapters
│ └── ArticleGetter.go
|
├── entities
│ └── responses
│ ├── TopicsAPIResponse.go
│ └── contents
│ └── Article.go
├── repositories
│ └── NewsApiRepository.go
├── router.go
└── services
└── TopicsArticleService.go