55 lines
1.4 KiB
Markdown
55 lines
1.4 KiB
Markdown
# GeoIP REST (Go Fiber)
|
|
|
|
간단한 GeoIP 조회 API입니다. `GeoLite2-City.mmdb`를 사용해 IP를 나라/지역/도시/위도/경도로 매핑합니다.
|
|
|
|
## 요구 사항
|
|
- Go 1.25+
|
|
- `GeoLite2-City.mmdb` (레포지토리 루트에 위치)
|
|
- Docker / Docker Compose (컨테이너 실행 시)
|
|
|
|
## 설치 및 실행
|
|
### 로컬 (Go)
|
|
```bash
|
|
go mod tidy # 필요한 경우 go.sum 생성
|
|
PORT=8080 GEOIP_DB_PATH=./GeoLite2-City.mmdb go run ./cmd/server
|
|
```
|
|
|
|
### Docker Compose
|
|
```bash
|
|
docker compose up --build
|
|
```
|
|
- `GeoLite2-City.mmdb`가 컨테이너에 read-only로 마운트됩니다.
|
|
- 기본 포트: `8080`.
|
|
|
|
## 환경 변수
|
|
- `PORT` (기본 `8080`): 서버 리스닝 포트
|
|
- `GEOIP_DB_PATH` (기본 `/data/GeoLite2-City.mmdb`): GeoIP 데이터베이스 경로
|
|
|
|
## 사용법
|
|
- 헬스체크: `GET /health`
|
|
- 조회: `GET /lookup?ip=<IPv4|IPv6>`
|
|
- `ip` 생략 시 호출자 IP를 사용
|
|
|
|
예시:
|
|
```bash
|
|
curl "http://localhost:8080/lookup?ip=1.1.1.1"
|
|
```
|
|
|
|
응답 예시:
|
|
```json
|
|
{
|
|
"IP": "1.1.1.1",
|
|
"Country": "Australia",
|
|
"Region": "Queensland",
|
|
"City": "South Brisbane",
|
|
"Address": "South Brisbane, Queensland, Australia",
|
|
"Latitude": -27.4748,
|
|
"Longitude": 153.017
|
|
}
|
|
```
|
|
|
|
## 개발 참고
|
|
- 주요 코드: `cmd/server/main.go`, `internal/geo/resolver.go`
|
|
- 테스트 실행: `go test ./...`
|
|
- 컨테이너 빌드: `docker build -t geoip:local .`
|