Высоконагруженный REST-сервис для внутреннего магазина компании.
Позволяет сотрудникам покупать мерч за монеты и переводить монеты друг другу.
- Go 1.25
- PostgreSQL 15
- Docker / Docker Compose
- JWT для авторизации
- chi — роутер
- testify — тестирование
| Эндпоинт | Метод | Описание | Авторизация |
|---|---|---|---|
/api/auth |
POST | Регистрация / вход | Нет |
/api/buy/{item} |
GET | Покупка мерча | Да |
/api/sendCoin |
POST | Перевод монет | Да |
/api/info |
GET | Информация о пользователе | Да |
git clone https://github.com/ваш-аккаунт/go-merch-shop.git
cd go-merch-shopDB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=merch-shop
DB_PORT=5432
DB_HOST=db
DB_SSLMODE=disable
SERVER_PORT=8080
JWT_SECRET=your-super-secret-keydocker-compose up --buildСервер будет доступен по адресу: http://localhost:8080
curl -X POST http://localhost:8080/api/auth \
-H "Content-Type: application/json" \
-d '{"username":"alex","password":"123"}'{"token":"eyJhbGciOiJIUzI1NiIs..."}curl -X GET http://localhost:8080/api/buy/t-shirt \
-H "Authorization: Bearer <токен>""мерч успешно приобретен"curl -X POST http://localhost:8080/api/sendCoin \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <токен>" \
-d '{"toUser":"ivan","amount":100}'"монеты успешно отправлены"curl -X GET http://localhost:8080/api/info \
-H "Authorization: Bearer <токен>"{
"coins": 850,
"inventory": [
{"type": "t-shirt", "quantity": 2}
],
"coinHistory": {
"received": [
{"fromUser": "ivan", "amount": 50}
],
"sent": [
{"toUser": "ivan", "amount": 100}
]
}
}go test -cover ./internal/service/...handlers → services → repository → PostgreSQL
- Handlers — HTTP-слой (валидация, таймауты)
- Services — бизнес-логика
- Repository — работа с БД (транзакции, индексы)
🐙 GitHub: gopher-95 📧 Email: gopher-95@yandex.ru