catchreview-api-app's Introduction
catchreview-api-app's People
catchreview-api-app's Issues
Makefile 을 활용한 빌드 자동화
Makefile 을 활용한 빌드 자동화
Go build 를 Makefile 과 Dockerfile 을 활용해서 빌드를 자동화합니다.
Makefile 은 Go Build 와 Docker Build, Push 를 자동화합니다.
Makefile
Makefile 은 build, docker-build, docker-push, docker-release 등으로 구성되어 있습니다.
프로젝트의 빌드는 Docker Image 안에서 진행하기 때문에 Make 는 docker-build
, docker-push
로 이루어져 있습니다.
Dockerfile 내에서 make build
명령어를 사용합니다.
Dockerfile
Dockerfile 을 통해 이미지를 빌드합니다.
이때 Multi-Stage Build 를 통해 Go Build 를 로컬이 아닌 도커 이미지에서 수행합니다.
AWS ECR
도커 이미지 저장소로 public AWS ECR 을 선택하였습니다.
해당 레파지토리에 대한 Docker push 에 대한 자동화를 진행하였습니다.
[Member] 회원가입 API
Member API 를 구성하는데 앞서 Layout 에 대해 고민이 필요합니다.
목표는 테스트코드를 작성하는데 있어 프로젝트 구조를 3-tier 계층으로 분리하는데 있습니다.
( Presentation Layer, Service Layer, Infrastructure Layer )
Reference
표준 Go 프로젝트 레이아웃 (https://github.com/golang-standards/project-layout/blob/master/README_ko.md)
Go Clean Architecture Example (https://github.com/bxcodec/go-clean-arch)
SWAGGER 문서 적용 및 Readme 작성
HTTP Web 프레임워크 적용
HTTP Web Framework 선택
catchreview-api-app 을 구성하는데 있어 Http Web Framework 적용을 필요로 함
REST API 를 구성하는데 있어 아래와 같은 기능을 필요로 함
- 라우팅 : HTTP 웹 프레임워크는 URL 경로와 해당 경로에 대해 핸들러를 매핑
- 미들웨어 : 로깅, 인증, 권한 부여, 캐싱 등과 같은 공통 기능 관리
- 세션 및 쿠키처리 : 사용자 세션을 관리, 쿠키를 처리하는 기능
Follow, 지도 기반의 맛집 지도 서비스로 Side-Project 를 지향함
- 확장성 : 현재는 Follow, 지도 기반의 맛집 지도 서비스로 Side-Project 를 목표로 함
- 복잡도 : 가게, 리뷰, 회원 인 3개의 도메인을 중점으로 간단한 서비스를 목표로 함
golang 에서 http framework 로 Gin(stars: 70715), Echo(stars: 26282), Fiber(stars: 27759) 등이 존재함
(reference: https://github.com/mingrammer/go-web-framework-stars)
결론
Gin gonic Framework 선택 : 가게, 리뷰, 회원 인 3개의 도메인을 중점으로 가벼운 REST API 목표
Gin
- 경량하고 빠른 프레임워크를 선호하는 경우.
- 미들웨어 지원을 통해 간단한 기능 추가 및 로직 처리가 필요한 경우.
- 복잡한 라우팅 및 핸들링을 다루기 위해 미들웨어 체인을 구성하고자 하는 경우.
- 빠른 개발과 성능에 중점을 둘 경우.
Echo
- 빠른 라우팅 및 핸들링 처리가 필요한 경우.
- 단순하고 직관적인 API 디자인을 선호하는 경우.
- 미들웨어를 사용하여 인증, 권한 부여, 로깅 등의 추가 기능을 구현하고자 하는 경우.
- HTTP/2와 WebSocket 지원 등 고급 기능이 필요한 경우.
fiber
- Fibre 는 fasthttp 를 탑재한 웹 프레임워크
- Fiber는 빠른 라우팅 및 핸들링을 통해 높은 성능을 필요로 하는 경우
- Fiber는 비동기 I/O 작업을 지원하여 다중 요청을 동시에 처리하는 경우
- 미들웨어를 사용하여 인증, 권한 부여, 로깅 등의 추가 기능을 구현하고자 하는 경우.
- Fiber는 WebSocket 지원을 통해 실시간 통신 기능을 구현하는 경우
Gin Graceful Shutdown 적용
Graceful Shutdown 적용
메인 쓰레드에 의한 강제 종료가 아닌 Graceful Shutdown 로직을 적용합니다.
- Graceful Shutdown 이란, 자식 쓰레드가 모두 종료된 이후 부모 쓰레드가 종료되는 로직을 의미합니다.
waitgroup 과 context 를 사용하여 cancel 명령을 수신받았을 때 server 를 shutdown 합니다.
context 를 사용하는데 있어 주의사항
- context.Background 는 프로그램의 최상위 레벨에서 사용되는게 바람직합니다.
- context 를 struct 안에 담지 말아야합니다. function 에 넘긴다면 첫번째 argument 로 넘기는 것이 좋습니다.
- context 는 cancel method 가 없습니다. context 를 derive 하는 함수만 캔슬할 수 있어야 하기 때문입니다.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.