server

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

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

type Handler struct {
	Storage           *Storage
	RegistrationToken string
}

func NewHandler

func NewHandler(storage *Storage) *Handler

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) GetUser

func (h *Handler) GetUser(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) ListFiles

func (h *Handler) ListFiles(w http.ResponseWriter, r *http.Request)

func (*Handler) Ping

func (h *Handler) Ping(w http.ResponseWriter, r *http.Request)

func (*Handler) RegisterUser

func (h *Handler) RegisterUser(w http.ResponseWriter, r *http.Request)

func (*Handler) SetRegistrationToken added in v1.0.4

func (h *Handler) SetRegistrationToken(token string)

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

func (*LocalBlobStore) Get

func (s *LocalBlobStore) Get(id string) ([]byte, error)

func (*LocalBlobStore) Save

func (s *LocalBlobStore) Save(id string, content []byte) error

type S3BlobStore

type S3BlobStore struct {
	Client S3ClientAPI
	Bucket string
}

S3BlobStore implements BlobStore using AWS S3.

func NewS3BlobStore

func NewS3BlobStore(ctx context.Context, bucket string, region string) (*S3BlobStore, error)

func (*S3BlobStore) Delete

func (s *S3BlobStore) Delete(id string) error

func (*S3BlobStore) Get

func (s *S3BlobStore) Get(id string) ([]byte, error)

func (*S3BlobStore) Save

func (s *S3BlobStore) Save(id string, content []byte) 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.

func NewServer

func NewServer(port string, storageDir string) (*Server, error)

NewServer initializes a new Server.

func (*Server) Start

func (s *Server) Start() error

Start starts the 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

func NewStorage(baseDir string, blobStore BlobStore) (*Storage, error)

NewStorage creates a new Storage instance.

func (*Storage) AddUser

func (s *Storage) AddUser(user models.User) error

AddUser adds or updates a user.

func (*Storage) CreateChallenge added in v1.0.4

func (s *Storage) CreateChallenge(username string, nonce string)

CreateChallenge generates and stores a nonce for a user.

func (*Storage) CreateSession added in v1.0.4

func (s *Storage) CreateSession(session models.Session)

CreateSession stores a new session.

func (*Storage) DeleteFile

func (s *Storage) DeleteFile(id string) error

DeleteFile removes a file and its metadata.

func (*Storage) DeleteSession added in v1.0.4

func (s *Storage) DeleteSession(token string)

DeleteSession removes a session.

func (*Storage) GetChallenge added in v1.0.4

func (s *Storage) GetChallenge(username string) (string, bool)

GetChallenge retrieves and deletes a challenge for a user.

func (*Storage) GetFileContent

func (s *Storage) GetFileContent(id string) ([]byte, error)

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

func (s *Storage) GetSession(token string) (models.Session, bool)

GetSession retrieves a session by token.

func (*Storage) GetUser

func (s *Storage) GetUser(username string) (models.User, bool)

GetUser retrieves a user by username.

func (*Storage) ListFiles

func (s *Storage) ListFiles(recipient string) []models.FileMetadata

ListFiles returns files for a specific recipient.

func (*Storage) SaveFile

func (s *Storage) SaveFile(metadata models.FileMetadata, content []byte) error

SaveFile saves a file and its metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL