refactor: rewrite project from Rust to Go
- Replace Axum with Chi router - Replace sqlx with pgx for PostgreSQL - Replace tonic/prost with grpc-go - Replace tracing with zerolog - Update flake.nix for Go build with protoc generation - Preserve all existing endpoints and functionality Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package torrent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotConnected = errors.New("not connected")
|
||||
ErrAuthFailed = errors.New("authentication failed")
|
||||
ErrTorrentNotFound = errors.New("torrent not found")
|
||||
ErrInvalidRequest = errors.New("invalid request")
|
||||
ErrConnectionFailed = errors.New("connection failed")
|
||||
)
|
||||
|
||||
type TorrentState string
|
||||
|
||||
const (
|
||||
StateDownloading TorrentState = "downloading"
|
||||
StateSeeding TorrentState = "seeding"
|
||||
StatePaused TorrentState = "paused"
|
||||
StateQueued TorrentState = "queued"
|
||||
StateChecking TorrentState = "checking"
|
||||
StateError TorrentState = "error"
|
||||
StateUnknown TorrentState = "unknown"
|
||||
)
|
||||
|
||||
type TorrentInfo struct {
|
||||
Hash string `json:"hash"`
|
||||
Name string `json:"name"`
|
||||
Size uint64 `json:"size"`
|
||||
Progress float64 `json:"progress"`
|
||||
DownloadSpeed uint64 `json:"download_speed"`
|
||||
UploadSpeed uint64 `json:"upload_speed"`
|
||||
State TorrentState `json:"state"`
|
||||
SavePath string `json:"save_path"`
|
||||
}
|
||||
|
||||
type Client interface {
|
||||
Connect(ctx context.Context) error
|
||||
Disconnect(ctx context.Context) error
|
||||
ListTorrents(ctx context.Context) ([]TorrentInfo, error)
|
||||
GetTorrent(ctx context.Context, hash string) (*TorrentInfo, error)
|
||||
AddTorrentURL(ctx context.Context, url string, savePath *string) error
|
||||
AddTorrentFile(ctx context.Context, data []byte, savePath *string) error
|
||||
RemoveTorrent(ctx context.Context, hash string, deleteFiles bool) error
|
||||
PauseTorrent(ctx context.Context, hash string) error
|
||||
ResumeTorrent(ctx context.Context, hash string) error
|
||||
}
|
||||
Reference in New Issue
Block a user