golang-template/internal/handlers/handler.go
2026-08-15 23:57:52 +03:00

32 lines
760 B
Go

package handlers
import (
"go-backend/internal/auth"
"go-backend/internal/database"
)
// UserService and AuthService are defined here, on the consumer side, so
// handlers depend only on the methods they actually use and tests can swap
// in fakes without touching the services package.
type UserService interface {
FindByID(id string) (*database.User, error)
FindByUsername(username string) (*database.User, error)
}
type AuthService interface {
CreateSession(userID string) (*auth.SessionWithToken, error)
ValidateSessionToken(token string) (*auth.Session, error)
}
type Handler struct {
users UserService
auth AuthService
}
func NewHandler(users UserService, auth AuthService) *Handler {
return &Handler{
users: users,
auth: auth,
}
}