This module handles HTTP network operations for fetching files from the vault repository on GitHub.
fmt: String formatting and printingio: I/O utilitiesnet/http: HTTP client and utilitiestime: Time package for cache busting
func FetchRaw(username string, path string) ([]byte, error)Fetches raw file content from a GitHub repository using the GitHub raw content API.
Parameters:
username: The GitHub username hosting the vault (e.g., "myuser")path: The path to the file in the repository (e.g., "storage_id_hex" or ".config/index")
Return:
[]byte: The raw file contenterror: Returns error if the request fails or file is not found
URL Format:
Files are fetched using GitHub's raw content API with a timestamp cache buster:
https://raw.githubusercontent.com/{username}/.zephyrus/master/{path}?t={nanoseconds}
Process:
- Constructs the GitHub raw URL with cache buster query parameter
- Creates an HTTP client with 10-second timeout
- Makes GET request to fetch the file
- Returns file content or error
Error Handling:
- Returns "404" error if file is not found (StatusCode 404)
- Returns "bad status: {code}" error for other HTTP errors
- Returns network-related errors if the request fails
Special Features:
- Cache Busting: Uses
time.Now().UnixNano()as query parameter to bypass browser/CDN caching - Timeout: 10-second timeout prevents hanging on network issues
- Direct: Uses raw GitHub API for direct file access without HTML wrapper
Example Usage:
// Fetch an encrypted file
data, err := FetchRaw("myusername", "a3f2e1c9d4b6f8e2")
if err != nil {
log.Fatal(err)
}
// Fetch the vault index
indexData, err := FetchRaw("myusername", ".config/index")
if err != nil {
if err.Error() == "404" {
fmt.Println("Index not found - new vault")
} else {
log.Fatal(err)
}
}- Downloading Files: Fetch encrypted file by storage ID
- Fetching Master Key: Fetch
.config/keyat setup - Fetching Index: Fetch
.config/indexto get vault structure
- Files must exist in the
.zephyrusGitHub repository - The repository can be private (accessed via SSH for git operations, but FetchRaw requires public access or GitHub token)
- Cache busting ensures fresh data on each request
- 10-second timeout is suitable for typical network conditions
- Error message "404" is specifically checked by caller code