- Add go.mod (module tanabata/backend, Go 1.21) with uuid dependency - Implement internal/domain: File, Tag, TagRule, Category, Pool, PoolFile, User, Session, Permission, ObjectType, AuditEntry + all pagination types - Add domain error sentinels (ErrNotFound, ErrForbidden, etc.) - Add context helpers WithUser/UserFromContext for JWT propagation - Fix migration: remove redundant DEFAULT on exif jsonb column Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
478 B
Go
25 lines
478 B
Go
package domain
|
|
|
|
import "context"
|
|
|
|
type ctxKey int
|
|
|
|
const userKey ctxKey = iota
|
|
|
|
type contextUser struct {
|
|
ID int16
|
|
IsAdmin bool
|
|
}
|
|
|
|
func WithUser(ctx context.Context, userID int16, isAdmin bool) context.Context {
|
|
return context.WithValue(ctx, userKey, contextUser{ID: userID, IsAdmin: isAdmin})
|
|
}
|
|
|
|
func UserFromContext(ctx context.Context) (userID int16, isAdmin bool) {
|
|
u, ok := ctx.Value(userKey).(contextUser)
|
|
if !ok {
|
|
return 0, false
|
|
}
|
|
return u.ID, u.IsAdmin
|
|
}
|