added auth service to go backend

This commit is contained in:
2025-01-03 20:45:39 +00:00
parent 98fb6942fe
commit d0d88de15c
10 changed files with 297 additions and 9 deletions
@@ -5,16 +5,17 @@ type ErrorCode string
const (
// General errors
InternalError ErrorCode = "internal_error"
ValidationError ErrorCode = "validation_error"
NotFoundError ErrorCode = "not_found"
UnauthorizedError ErrorCode = "unauthorized"
ForbiddenError ErrorCode = "forbidden"
ConflictError ErrorCode = "conflict"
DatabaseError ErrorCode = "database_error"
InternalError ErrorCode = "internal_error"
ValidationError ErrorCode = "validation_error"
NotFoundError ErrorCode = "not_found"
UnauthorizedError ErrorCode = "unauthorized"
ForbiddenError ErrorCode = "forbidden"
ConflictError ErrorCode = "conflict"
DatabaseError ErrorCode = "database_error"
ExternalServiceError ErrorCode = "external_service_error"
AuthError ErrorCode = "auth_error"
// Specific errors
UserNotFoundError ErrorCode = "user_not_found"
UserNotFoundError ErrorCode = "user_not_found"
ProjectNotFoundError ErrorCode = "project_not_found"
)
@@ -23,3 +23,8 @@ func NewUnauthorizedError(message string) *AppError {
func NewInternalError(err error) *AppError {
return Wrap(err, InternalError, "An internal server error occurred", http.StatusInternalServerError)
}
// NewAuthError creates an authentication error.
func NewAuthError(message string) *AppError {
return New(AuthError, message, http.StatusUnauthorized)
}
@@ -0,0 +1,13 @@
package repository
import (
"context"
E "github.com/IBM/fp-go/either"
)
type AuthRepository interface {
GenerateToken(ctx context.Context) func(userID string) E.Either[error, string]
ValidateToken(ctx context.Context) func(userID string) E.Either[error, string]
RevokeToken(ctx context.Context) func(userID string) E.Either[error, string]
}