Documentation
¶
Index ¶
- type BlobStore
- type Handler
- func (h *Handler) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc
- func (h *Handler) DeleteFile(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DownloadFile(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleGetChallenge(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListFiles(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Ping(w http.ResponseWriter, r *http.Request)
- func (h *Handler) RegisterUser(w http.ResponseWriter, r *http.Request)
- func (h *Handler) SetRegistrationToken(token string)
- func (h *Handler) UploadFile(w http.ResponseWriter, r *http.Request)
- type LocalBlobStore
- type S3BlobStore
- type S3ClientAPI
- type Server
- type Storage
- func (s *Storage) AddUser(user models.User) error
- func (s *Storage) CreateChallenge(username string, nonce string)
- func (s *Storage) CreateSession(session models.Session)
- func (s *Storage) DeleteFile(id string) error
- func (s *Storage) DeleteSession(token string)
- func (s *Storage) GetChallenge(username string) (string, bool)
- func (s *Storage) GetFileContent(id string) ([]byte, error)
- func (s *Storage) GetFileMetadata(id string) (models.FileMetadata, bool)
- func (s *Storage) GetSession(token string) (models.Session, bool)
- func (s *Storage) GetUser(username string) (models.User, bool)
- func (s *Storage) ListFiles(recipient string) []models.FileMetadata
- func (s *Storage) SaveFile(metadata models.FileMetadata, content []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlobStore ¶
type BlobStore interface {
Save(id string, content []byte) error
Get(id string) ([]byte, error)
Delete(id string) error
}
BlobStore defines the interface for storing file content.
type Handler ¶
func NewHandler ¶
func (*Handler) AuthMiddleware ¶ added in v1.0.4
func (h *Handler) AuthMiddleware(next http.HandlerFunc) http.HandlerFunc
AuthMiddleware protects routes by requiring a valid session token.
func (*Handler) DeleteFile ¶ added in v1.0.4
func (h *Handler) DeleteFile(w http.ResponseWriter, r *http.Request)
DeleteFile deletes a file if the user is the sender or recipient.
func (*Handler) DownloadFile ¶
func (h *Handler) DownloadFile(w http.ResponseWriter, r *http.Request)
func (*Handler) HandleGetChallenge ¶ added in v1.0.4
func (h *Handler) HandleGetChallenge(w http.ResponseWriter, r *http.Request)
HandleGetChallenge generates a random nonce for the user.
func (*Handler) HandleLogin ¶ added in v1.0.4
func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLogin verifies the challenge response and issues a session token.
func (*Handler) RegisterUser ¶
func (h *Handler) RegisterUser(w http.ResponseWriter, r *http.Request)
func (*Handler) SetRegistrationToken ¶ added in v1.0.4
SetRegistrationToken sets the registration token for the handler.
func (*Handler) UploadFile ¶
func (h *Handler) UploadFile(w http.ResponseWriter, r *http.Request)
type LocalBlobStore ¶
type LocalBlobStore struct {
BaseDir string
}
LocalBlobStore implements BlobStore using the local filesystem.
func NewLocalBlobStore ¶
func NewLocalBlobStore(baseDir string) *LocalBlobStore
func (*LocalBlobStore) Delete ¶
func (s *LocalBlobStore) Delete(id string) error
type S3BlobStore ¶
type S3BlobStore struct {
Client S3ClientAPI
Bucket string
}
S3BlobStore implements BlobStore using AWS S3.
func NewS3BlobStore ¶
func (*S3BlobStore) Delete ¶
func (s *S3BlobStore) Delete(id string) error
type S3ClientAPI ¶
type S3ClientAPI interface {
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
}
S3ClientAPI defines the interface for S3 operations we use.
type Server ¶
type Server struct {
Port string
Storage *Storage
Handler *Handler
Server *http.Server
RegistrationToken string
}
Server represents the HTTP server.
type Storage ¶
type Storage struct {
BaseDir string
Users map[string]models.User
Files map[string]models.FileMetadata
BlobStore BlobStore
Challenges map[string]string // username -> nonce
Sessions map[string]models.Session // token -> session
// contains filtered or unexported fields
}
Storage handles persistence for users and files.
func NewStorage ¶
NewStorage creates a new Storage instance.
func (*Storage) CreateChallenge ¶ added in v1.0.4
CreateChallenge generates and stores a nonce for a user.
func (*Storage) CreateSession ¶ added in v1.0.4
CreateSession stores a new session.
func (*Storage) DeleteFile ¶
DeleteFile removes a file and its metadata.
func (*Storage) DeleteSession ¶ added in v1.0.4
DeleteSession removes a session.
func (*Storage) GetChallenge ¶ added in v1.0.4
GetChallenge retrieves and deletes a challenge for a user.
func (*Storage) GetFileContent ¶
GetFileContent retrieves the content of a file.
func (*Storage) GetFileMetadata ¶
func (s *Storage) GetFileMetadata(id string) (models.FileMetadata, bool)
GetFileMetadata retrieves metadata for a file.
func (*Storage) GetSession ¶ added in v1.0.4
GetSession retrieves a session by token.