Go 언어로 구현한 쇼핑몰 백엔드 API 서버입니다. Clean Architecture 패턴을 적용하여 확장성과 유지보수성을 고려했습니다.
shopping-mall-backend/
├── config/ # 설정 관리
├── controllers/ # HTTP 핸들러 (Presentation Layer)
├── services/ # 비즈니스 로직 (Business Layer)
├── repositories/ # 데이터 접근 (Data Access Layer)
├── models/ # 데이터 모델
├── middleware/ # HTTP 미들웨어
├── routes/ # 라우팅 설정
├── pkg/
│ ├── errors/ # 에러 정의
│ └── response/ # 응답 표준화
└── database/ # 데이터베이스 연결
- 언어: Go 1.24.5
- 웹 프레임워크: Gin
- ORM: GORM
- 데이터베이스: SQLite
- 아키텍처: Clean Architecture
- 패턴: Repository Pattern, Dependency Injection
GET /api/v1/categories
- 모든 카테고리 조회GET /api/v1/categories/:id
- 특정 카테고리 조회POST /api/v1/categories
- 카테고리 생성PUT /api/v1/categories/:id
- 카테고리 수정DELETE /api/v1/categories/:id
- 카테고리 삭제GET /api/v1/categories/:id/products
- 카테고리별 상품 조회
GET /api/v1/products
- 모든 상품 조회GET /api/v1/products/:id
- 특정 상품 조회POST /api/v1/products
- 상품 생성PUT /api/v1/products/:id
- 상품 수정DELETE /api/v1/products/:id
- 상품 삭제
GET /api/v1/users
- 모든 사용자 조회GET /api/v1/users/:id
- 특정 사용자 조회POST /api/v1/users
- 사용자 생성PUT /api/v1/users/:id
- 사용자 수정DELETE /api/v1/users/:id
- 사용자 삭제
git clone https://github.com/DongilMin/go-lang-side-project.git
cd shopping-mall-backend
go mod download
export DB_DRIVER=sqlite
export DB_DSN=shopping_mall.db
export SERVER_PORT=:8080
export GIN_MODE=debug
go run main.go
서버가 http://localhost:8080
에서 실행됩니다.
{
"success": true,
"data": {
"id": 1,
"name": "Electronics",
"created_at": "2025-07-18T20:14:57Z"
}
}
{
"success": false,
"error": "category not found"
}
curl -X POST http://localhost:8080/api/v1/categories \
-H "Content-Type: application/json" \
-d '{"name": "Electronics"}'
curl -X POST http://localhost:8080/api/v1/products \
-H "Content-Type: application/json" \
-d '{
"name": "iPhone 15",
"description": "Latest Apple smartphone",
"price": 999.99,
"stock": 50,
"category_id": 1
}'
curl -X POST http://localhost:8080/api/v1/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "[email protected]",
"phone": "010-1234-5678",
"address": "Seoul, Korea"
}'
- Controller: HTTP 요청/응답 처리
- Service: 비즈니스 로직 구현
- Repository: 데이터 접근 추상화
- Model: 데이터 구조 정의
- 인터페이스 기반 의존성 관리
- 테스트 가능한 구조
- 느슨한 결합
- 표준화된 에러 정의
- 일관된 에러 응답 형식
이 프로젝트는 다음 개념들을 학습하기 위해 만들어졌습니다:
- Go 언어 기본 문법
- Gin 웹 프레임워크
- GORM ORM 사용법
- Clean Architecture 패턴
- Repository 패턴
- 의존성 주입
- RESTful API 설계