Documentation
¶
Overview ¶
Package vfssrv provides a client for interacting with a Virtual File System (VFS) service. It supports authentication, file uploads, and file downloads with proper error handling.
Index ¶
- Variables
- func HashURL(hash string) string
- type Client
- func (c *Client) AuthToken(ctx context.Context) (string, error)
- func (c *Client) DownloadFile(ctx context.Context, namespace, hash, ext, size string) ([]byte, error)
- func (c *Client) DownloadImage(ctx context.Context, namespace, hash, size string) ([]byte, error)
- func (c *Client) FilePath(namespace, hash, size, ext string) (string, error)
- func (c *Client) UploadFile(ctx context.Context, token, namespace, filename string, file io.Reader) (*HashUploadResponse, error)
- type HashUploadResponse
- type Opts
- type RequestError
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrInternal = errors.New("internal error") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) DownloadFile ¶
func (c *Client) DownloadFile(ctx context.Context, namespace, hash, ext, size string) ([]byte, error)
DownloadFile downloads vfs file and returns bytes. Size and extension could be empty.
func (*Client) DownloadImage ¶
DownloadImage DownloadFile downloads vfs image with default extension and returns bytes.
func (*Client) FilePath ¶
FilePath constructs a URL for accessing a media image in the VFS. It returns an empty string and no error if the hash is not 32 characters. The URL format is: base_url/namespace/size/hash_path.jpg
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, token, namespace, filename string, file io.Reader) (*HashUploadResponse, error)
UploadFile uploads File to VFS. Filename with extension. Use empty namespace for default.
type HashUploadResponse ¶
type HashUploadResponse struct {
Error string `json:"error,omitempty"` // error message
Hash string `json:"hash,omitempty"` // for hash
Extension string `json:"ext,omitempty"` // vfs file ext
WebPath string `json:"webPath,omitempty"` // for hash
FileID int `json:"id,omitempty"` // vfs file id
Name string `json:"name,omitempty"` // vfs file name
}
type Opts ¶
type Opts struct {
ApiURL string // Base URL for API endpoints
PublicURL string // Base URL for Public Files
Timeout time.Duration // HTTP request timeout, default is 5s
UploadFormName string // Form field name for file uploads, default is Filedata
AuthHeader string // Header name for authentication, default is AuthorizationJWT
Client *http.Client // Custom HTTP client (optional)
}
type RequestError ¶
RequestError records an error, URL and code.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error