refactor(auth): move auth package to service directory

Relocated internal/auth to internal/service/auth for improved project
structure
and separation of concerns. Updated all imports to reflect new paths.
Split
UserStore interface and error definitions into a dedicated store.go
file.
Moved generateUserID to user.go for better encapsulation.
This commit is contained in:
Ruidy 2025-09-20 13:04:13 +02:00
parent d0311ccd24
commit d642716fd0
No known key found for this signature in database
GPG key ID: 705C24D202990805
8 changed files with 32 additions and 27 deletions

View file

@ -5,7 +5,7 @@ import (
"log" "log"
"net/http" "net/http"
"github.com/rjnemo/auth/internal/auth" "github.com/rjnemo/auth/internal/service/auth"
) )
const ( const (

View file

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/rjnemo/auth/internal/auth" "github.com/rjnemo/auth/internal/service/auth"
) )
const dashboardTimeDisplayLayout = "02 Jan 2006 15:04 MST" const dashboardTimeDisplayLayout = "02 Jan 2006 15:04 MST"

View file

@ -7,7 +7,7 @@ import (
"html/template" "html/template"
"time" "time"
"github.com/rjnemo/auth/internal/auth" "github.com/rjnemo/auth/internal/service/auth"
"github.com/rjnemo/auth/web" "github.com/rjnemo/auth/web"
) )

View file

@ -2,8 +2,6 @@ package auth
import ( import (
"context" "context"
"crypto/rand"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"time" "time"
@ -96,12 +94,3 @@ func (s *Service) Register(ctx context.Context, email UserEmail, password string
return &user, nil return &user, nil
} }
// TODO: could be UUID. return a dedicated type
func generateUserID() (string, error) {
buf := make([]byte, userIDByteLength)
if _, err := rand.Read(buf); err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(buf), nil
}

View file

@ -0,0 +1,18 @@
package auth
import (
"context"
"errors"
)
// ErrUserNotFound signals no user exists for the provided lookup criteria.
var (
ErrUserNotFound = errors.New("auth: user not found")
ErrEmailRequired = errors.New("auth: email required")
)
// UserStore defines persistence expectations for user lookups.
type UserStore interface {
FindByEmail(ctx context.Context, email UserEmail) (*User, error)
Create(ctx context.Context, user User) error
}

View file

@ -2,22 +2,9 @@ package auth
import ( import (
"context" "context"
"errors"
"sync" "sync"
) )
// ErrUserNotFound signals no user exists for the provided lookup criteria.
var (
ErrUserNotFound = errors.New("auth: user not found")
ErrEmailRequired = errors.New("auth: email required")
)
// UserStore defines persistence expectations for user lookups.
type UserStore interface {
FindByEmail(ctx context.Context, email UserEmail) (*User, error)
Create(ctx context.Context, user User) error
}
// MemoryStore is an in-memory implementation of UserStore for development and tests. // MemoryStore is an in-memory implementation of UserStore for development and tests.
type MemoryStore struct { type MemoryStore struct {
mu sync.RWMutex mu sync.RWMutex

View file

@ -1,6 +1,8 @@
package auth package auth
import ( import (
"crypto/rand"
"encoding/base64"
"errors" "errors"
"strings" "strings"
"time" "time"
@ -45,3 +47,12 @@ func (e UserEmail) String() string {
func (e UserEmail) IsZero() bool { func (e UserEmail) IsZero() bool {
return e == "" return e == ""
} }
// TODO: could be UUID. return a dedicated type
func generateUserID() (string, error) {
buf := make([]byte, userIDByteLength)
if _, err := rand.Read(buf); err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(buf), nil
}