Microservice for managing LinkKeeper users.
User Service automatically registers users on their first interaction with the bot and provides an API for personalization.
- ✅ Automatic user registration from Telegram
- ✅ Data storage: Telegram ID, username, first name, last name
- ✅ User existence check
- ✅ Get user by Telegram ID
- ✅ GetOrCreate pattern (get or create)
Create or get existing user (GetOrCreate)
Request:
{
"telegram_id": 123456789,
"username": "testuser",
"first_name": "John",
"last_name": "Doe"
}Response:
{
"id": "uuid",
"telegram_id": 123456789,
"username": "testuser",
"first_name": "John",
"last_name": "Doe",
"created_at": "2026-01-15T21:20:01Z",
"updated_at": "2026-01-15T21:20:01Z"
}Get user by UUID
Response: JSON with user data
Get user by Telegram ID
Response: JSON with user data
Check if user exists
Response:
{
"exists": true
}Health check endpoint
Response: OK
task starttask user:runEnvironment variables:
HTTP_ADDR- address for HTTP server (default:8081)POSTGRES_DSN- PostgreSQL connection string
Bot Service automatically registers users on /start command:
- User sends
/startto the bot - Bot-service sends data to User-service
- User-service creates user or returns existing one
- User can use bot features
id(UUID) - unique identifiertelegram_id(BIGINT) - Telegram user ID (unique)username(VARCHAR) - Telegram usernamefirst_name(VARCHAR) - first namelast_name(VARCHAR) - last namecreated_at(TIMESTAMP) - creation dateupdated_at(TIMESTAMP) - update date
link_models.user_id→users.id(ON DELETE CASCADE)
# Create user
curl -X POST http://localhost:8081/api/v1/users \
-H "Content-Type: application/json" \
-d '{
"telegram_id": 123456789,
"username": "testuser",
"first_name": "Test",
"last_name": "User"
}'
# Check existence
curl http://localhost:8081/api/v1/users/telegram/123456789/exists
# Get user
curl http://localhost:8081/api/v1/users/telegram/123456789cmd/user-service/ # Entry point
internal/user-service/ # Business logic
├── models.go # Data models
├── repository.go # Repository interface
├── repository/
│ └── user.go # Repository implementation
├── usecase.go # Use case interface
├── usecase/
│ └── user.go # Use case implementation
└── transport/http/ # HTTP transport
├── http.go # Handlers
└── routers.go # Routes
User Service follows Clean Architecture:
- Models - data structure definitions
- Repository - database operations via GORM
- Use Case - business logic
- Transport - HTTP API (gorilla/mux)
Uses zerolog for structured logging.
- HTTP API:
8081