### Install go-get-release using go get Source: https://github.com/rhysd/go-github-selfupdate/blob/master/cmd/go-get-release/README.md Installs the `go-get-release` command-line tool using the standard Go package management command. This makes the tool available in your system's PATH for immediate use. ```bash go get -u github.com/rhysd/go-github-selfupdate/cmd/go-get-release ``` -------------------------------- ### Prompt User for Self-Update in Go Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md This example demonstrates how to prompt the user before performing a self-update. It first detects the latest version, compares it with the current version, and then asks for user confirmation before downloading and applying the update. It utilizes standard Go libraries for input/output and file operations. ```go import ( "bufio" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" "log" "os" "fmt" ) const version = "1.2.3" func confirmAndSelfUpdate() { latest, found, err := selfupdate.DetectLatest("owner/repo") if err != nil { log.Println("Error occurred while detecting version:", err) return } v := semver.MustParse(version) if !found || latest.Version.LTE(v) { log.Println("Current version is the latest") return } fmt.Print("Do you want to update to", latest.Version, "? (y/n): ") input, err := bufio.NewReader(os.Stdin).ReadString('\n') if err != nil || (input != "y\n" && input != "n\n") { log.Println("Invalid input") return } if input == "n\n" { return } exe, err := os.Executable() if err != nil { log.Println("Could not locate executable path") return } if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { log.Println("Error occurred while updating binary:", err) return } log.Println("Successfully updated to version", latest.Version) } ``` -------------------------------- ### go-get-release - CLI for installing release binaries Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt This command-line tool functions similarly to `go get` but is designed to install pre-built release binaries directly from GitHub releases, rather than compiling from source. It simplifies the process of deploying applications that distribute their binaries through GitHub releases. ```bash # The documentation for go-get-release is incomplete in the provided text. # This is a placeholder for its usage instructions. ``` -------------------------------- ### Download and install GitHub release binary using go-get-release Source: https://github.com/rhysd/go-github-selfupdate/blob/master/cmd/go-get-release/README.md Demonstrates how to use the `go-get-release` tool to download and install the latest binary release of a specified GitHub-hosted package. The package name must begin with `github.com/`. The tool automatically handles downloading and placing the binary in the appropriate location (e.g., `$GOPATH/bin`). ```bash go-get-release github.com/tcnksm/ghr Command was updated to the latest version 0.5.4: /Users/you/.go/bin/ghr ``` -------------------------------- ### Install Specific Command from Repository with Multiple Binaries Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Installs a specific command (binary) from a GitHub repository that contains multiple binaries. This is useful when the desired tool is not the main binary in the repository. ```bash go-get-release github.com/owner/repo/cmd/mytool # Output: # Command was updated to the latest version 1.3.0: /home/user/go/bin/mytool # # Release Notes: # - Added new feature X ``` -------------------------------- ### Install go-github-selfupdate Tool Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Installs the go-github-selfupdate command-line tool using 'go install'. This command fetches the latest version of the specified tool from GitHub. ```bash go install github.com/rhysd/go-github-selfupdate/cmd/go-get-release@latest ``` -------------------------------- ### Install Tool from GitHub Release using go-get-release Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Installs or updates a tool from its GitHub release using the 'go-get-release' command. It automatically detects the latest version and updates the command in the Go binary path. ```bash go-get-release github.com/owner/repo # Output: # Command was updated to the latest version 1.3.0: /home/user/go/bin/repo # # Release Notes: # - Added new feature X # - Fixed bug Y ``` -------------------------------- ### Create Customized Updater with go-github-selfupdate Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Illustrates how to create a customized `Updater` instance using `selfupdate.NewUpdater` with a `Config` struct. This allows for configurations like GitHub Enterprise URLs, API tokens, and release filters, which are necessary for private repositories or enterprise environments. The example shows setting an API token, enterprise base URL, and a filter for specific release assets. ```go package main import ( "fmt" "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { // Configure for GitHub Enterprise with API token and release filtering config := selfupdate.Config{ APIToken: "ghp_xxxxxxxxxxxxxxxxxxxx", EnterpriseBaseURL: "https://github.mycompany.com/api/v3", Filters: []string{'.*linux.*amd64.*'}, // Only match Linux AMD64 releases } updater, err := selfupdate.NewUpdater(config) if err != nil { log.Fatal("Failed to create updater:", err) } current := semver.MustParse("1.0.0") release, err := updater.UpdateSelf(current, "internal/tool") if err != nil { log.Fatal("Update failed:", err) } if release.Version.GT(current) { fmt.Println("Updated to:", release.Version) } else { fmt.Println("Already at latest version") } } ``` -------------------------------- ### Get Specific Release Version in Go Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Retrieves detailed information about a specific release version from a GitHub repository, rather than just the latest. This is useful for downloading or inspecting a particular version of a tool. It returns release details including version, asset URL, and asset size. Requires the 'rhysd/go-github-selfupdate' package. ```go package main import ( "fmt" "log" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { // Get a specific version (v1.2.0) instead of latest release, found, err := selfupdate.DetectVersion("owner/repo", "v1.2.0") if err != nil { log.Fatal("Error detecting version:", err) } if !found { fmt.Println("Version v1.2.0 not found") return } fmt.Printf("Found version: %s\n", release.Version) fmt.Printf("Download URL: %s\n", release.AssetURL) fmt.Printf("Asset size: %d bytes\n", release.AssetByteSize) } ``` -------------------------------- ### Run Go Tests for Selfupdate Package Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md Provides commands to run tests for the `/selfupdate` package. It shows how to execute verbose tests and how to set the `GITHUB_TOKEN` environment variable to enable tests that require GitHub API access. ```shell $ go test -v ./selfupdate ``` ```shell $ export GITHUB_TOKEN="{token generated by you}" $ go test -v ./selfupdate ``` -------------------------------- ### Generate SHA256 Checksum for File Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md Demonstrates how to generate a SHA256 checksum for a file using the `sha256sum` command-line utility. The output is redirected to a file with the same name as the original file, appended with the `.sha256` suffix, which go-github-selfupdate can use for verification. ```shell sha256sum foo.zip > foo.zip.sha256 ``` -------------------------------- ### Generate ECDSA Signature for File Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md Illustrates how to generate an ECDSA signature for a file using the `openssl` command-line tool. The signature is created using a private key (`Test.pem`) and saved to a file with the `.sig` suffix, enabling signature verification by go-github-selfupdate. ```shell openssl dgst -sha256 -sign Test.pem -out foo.zip.sig foo.zip ``` -------------------------------- ### Perform Automatic Self-Update in Go Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md This snippet shows the simplest way to perform a self-update. It automatically detects the latest version from a specified GitHub repository and updates the current binary if a newer version is available. It requires the 'semver' and 'go-github-selfupdate' packages. ```go import ( "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) const version = "1.2.3" func doSelfUpdate() { v := semver.MustParse(version) latest, err := selfupdate.UpdateSelf(v, "myname/myrepo") if err != nil { log.Println("Binary update failed:", err) return } if latest.Version.Equals(v) { // latest version is the same as current version. It means current binary is up to date. log.Println("Current binary is the latest version", version) } else { log.Println("Successfully updated to version", latest.Version) log.Println("Release note:\n", latest.ReleaseNotes) } } ``` -------------------------------- ### Configure Self-Update for GitHub Enterprise in Go Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md This snippet demonstrates how to configure the self-update process for GitHub Enterprise. It involves creating an `Updater` instance with specific configuration, including the API token and the Enterprise base URL. This is useful for private repositories or when encountering rate limits with public repositories. ```go import ( "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) const version = "1.2.3" func doSelfUpdate(token string) { v := semver.MustParse(version) up, err := selfupdate.NewUpdater(selfupdate.Config{ APIToken: token, EnterpriseBaseURL: "https://github.your.company.com/api/v3", }) latest, err := up.UpdateSelf(v, "myname/myrepo") if err != nil { log.Println("Binary update failed:", err) return } if latest.Version.Equals(v) { // latest version is the same as current version. It means current binary is up to date. log.Println("Current binary is the latest version", version) } else { log.Println("Successfully updated to version", latest.Version) log.Println("Release note:\n", latest.ReleaseNotes) } } ``` -------------------------------- ### UncompressCommand - Extract executable from archive Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt This Go snippet shows how to use the `UncompressCommand` utility to extract a specific executable file from a downloaded archive. It supports various formats like tar.gz, tgz, tar.xz, gz, and xz, automatically detecting the format from the URL. The function takes the archive's content (io.Reader), the URL, and the name of the executable to extract. ```go package main import ( "fmt" "io" "log" "net/http" "os" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { url := "https://github.com/owner/repo/releases/download/v1.3.0/mytool_linux_amd64.tar.gz" resp, err := http.Get(url) if err != nil { log.Fatal("Download failed:", err) } defer resp.Body.Close() // Extract "mytool" executable from the archive executable, err := selfupdate.UncompressCommand(resp.Body, url, "mytool") if err != nil { log.Fatal("Extraction failed:", err) } // Write to file out, _ := os.OpenFile("mytool", os.O_WRONLY|os.O_CREATE, 0755) defer out.Close() written, _ := io.Copy(out, executable) fmt.Printf("Extracted executable: %d bytes written\n", written) } ``` -------------------------------- ### Enable Debugging Logs in Go Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md This snippet shows how to enable logging for debugging purposes in the go-github-selfupdate library. By default, the logger is disabled. Enabling it provides details about the self-update process. ```go selfupdate.EnableLog() ``` -------------------------------- ### Update Specific Command Binary using go-github-selfupdate Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Shows how to update a command binary located at a specific path to its latest version using `selfupdate.UpdateCommand`. This is useful when you need to update a binary different from the currently running executable. It requires the command's path, the current version, and the repository owner/name. ```go package main import ( "fmt" "log" "path/filepath" "go/build" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { cmdPath := filepath.Join(build.Default.GOPATH, "bin", "mytool") current := semver.MustParse("1.0.0") release, err := selfupdate.UpdateCommand(cmdPath, current, "owner/repo") if err != nil { log.Fatal("Update failed:", err) } if release.Version.Equals(current) { fmt.Println("Command is already at the latest version") } else { fmt.Printf("Updated %s to version %s\n", cmdPath, release.Version) } } ``` -------------------------------- ### Perform Self-Update in Go Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Updates the running executable to the latest version available in a specified GitHub repository. It checks the current version against the latest release, downloads the appropriate binary, and replaces the existing executable. Rollback is supported on failure. Requires the 'blang/semver' and 'rhysd/go-github-selfupdate' packages. ```go package main import ( "fmt" "log" "os" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) const version = "1.2.3" func main() { current := semver.MustParse(version) latest, err := selfupdate.UpdateSelf(current, "owner/repo") if err != nil { log.Fatal("Update failed:", err) } if latest.Version.Equals(current) { fmt.Println("Current binary is already the latest version:", version) } else { fmt.Println("Successfully updated to version:", latest.Version) fmt.Println("Release notes: ", latest.ReleaseNotes) } } ``` -------------------------------- ### Update from Direct URL using go-github-selfupdate Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Demonstrates how to update an executable from a direct download URL using the `selfupdate.UpdateTo` function. This method bypasses the GitHub API and is suitable for public URLs but not private repositories. It requires the asset URL and the path to the executable to be updated. ```go package main import ( "fmt" "log" "os" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { exe, err := os.Executable() if err != nil { log.Fatal("Could not get executable path:", err) } assetURL := "https://github.com/owner/repo/releases/download/v1.3.0/tool_linux_amd64.tar.gz" if err := selfupdate.UpdateTo(assetURL, exe); err != nil { log.Fatal("Update failed:", err) } fmt.Println("Binary updated successfully from:", assetURL) } ``` -------------------------------- ### detect-latest-release - CLI for detecting latest GitHub release Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt This is a command-line tool that detects and displays the latest release information for a given GitHub repository. It can output the version number, asset download URL, release page URL, or release notes. It supports repository names and full GitHub URLs as input. ```bash # Install the tool go install github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release@latest # Detect latest version of a repository detect-latest-release owner/repo # Output: 1.3.0 # Get asset download URL detect-latest-release -asset owner/repo # Output: https://github.com/owner/repo/releases/download/v1.3.0/tool_linux_amd64.tar.gz # Get release page URL detect-latest-release -url owner/repo # Output: https://github.com/owner/repo/releases/tag/v1.3.0 # Show version with release notes detect-latest-release -release-notes owner/repo # Output: # 1.3.0 # # Release Notes: # - Added new feature X # - Fixed bug Y # - Performance improvements # Works with full GitHub URLs detect-latest-release https://github.com/owner/repo # Output: 1.3.0 ``` -------------------------------- ### EnableLog/DisableLog - Control debug logging output Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt This Go code demonstrates how to enable and disable debug logging for the selfupdate process. Enabling logs can be useful for troubleshooting update issues by providing verbose output to stderr. Logs are disabled by default and should be turned off after debugging. ```go package main import ( "fmt" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { // Enable verbose logging for debugging selfupdate.EnableLog() current := semver.MustParse("1.0.0") release, err := selfupdate.UpdateSelf(current, "owner/repo") // Disable logging after debugging selfupdate.DisableLog() if err != nil { fmt.Println("Update failed:", err) return } fmt.Println("Updated to:", release.Version) } ``` -------------------------------- ### ECDSAValidator - Validate release signatures with ECDSA Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt This snippet demonstrates how to configure the selfupdate library to validate release asset signatures using ECDSA. It requires loading a public key from a PEM file and passing it to the ECDSAValidator. The validator checks for a .sig file alongside the release asset. ```go package main import ( "crypto/ecdsa" "crypto/x509" "encoding/pem" "fmt" "io/ioutil" "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { // Load public key for signature verification pubPEM, err := ioutil.ReadFile("release-signing-key.pem") if err != nil { log.Fatal("Failed to read public key:", err) } block, _ := pem.Decode(pubPEM) pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { log.Fatal("Failed to parse public key:", err) } // Configure with ECDSA validation config := selfupdate.Config{ Validator: &selfupdate.ECDSAValidator{ PublicKey: pub.(*ecdsa.PublicKey), }, } updater, err := selfupdate.NewUpdater(config) if err != nil { log.Fatal("Failed to create updater:", err) } current := semver.MustParse("1.0.0") // UpdateSelf will verify signature from tool_linux_amd64.tar.gz.sig release, err := updater.UpdateSelf(current, "owner/repo") if err != nil { log.Fatal("Update failed (possibly signature verification failed):", err) } fmt.Println("Signature verified, updated to version:", release.Version) } ``` -------------------------------- ### Validate Releases with SHA256 Checksums using go-github-selfupdate Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Demonstrates how to enable SHA256 hash validation for downloaded release assets using the `selfupdate.SHA2Validator`. When this validator is configured, the library expects a `.sha256` file alongside the release asset and will verify the downloaded file's integrity against this checksum. This enhances security by ensuring the downloaded binary has not been tampered with. ```go package main import ( "fmt" "log" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) func main() { // Configure with SHA256 validation config := selfupdate.Config{ Validator: &selfupdate.SHA2Validator{}, } updater, err := selfupdate.NewUpdater(config) if err != nil { log.Fatal("Failed to create updater:", err) } current := semver.MustParse("1.0.0") // UpdateSelf will now validate the download against tool_linux_amd64.tar.gz.sha256 release, err := updater.UpdateSelf(current, "owner/repo") if err != nil { // Error if hash validation fails log.Fatal("Update failed (possibly hash mismatch):", err) } fmt.Println("Update validated and completed, version:", release.Version) } ``` -------------------------------- ### Validator Interface for Release Validation in Go Source: https://github.com/rhysd/go-github-selfupdate/blob/master/README.md Defines the Validator interface for custom release validation logic. It includes methods for validating release bytes against asset bytes and specifying the suffix for the additional asset file. This is used for implementing custom validation mechanisms beyond built-in SHA256 or ECDSA. ```go package main // Validator represents an interface which enables additional validation of releases. type Validator interface { // Validate validates release bytes against an additional asset bytes. // See SHA2Validator or ECDSAValidator for more information. Validate(release, asset []byte) error // Suffix describes the additional file ending which is used for finding the // additional asset. Suffix() string } ``` -------------------------------- ### Self-Update Go CLI Tool Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Enables a Go command-line tool to update itself automatically. This function handles version detection, binary replacement, and rollback. ```go import "github.com/rhysd/go-github-selfupdate/selfupdate" func main() { // Example: Update the current executable // Replace "currentVersion" with the actual version string of your tool // Replace "owner/repo" with the GitHub repository path (e.g., "rhysd/go-github-selfupdate") if _, err := selfupdate.UpdateSelf("currentVersion", "owner/repo"); err != nil { // Handle error, e.g., log it or inform the user // fmt.Printf("Failed to update: %v\n", err) } } ``` -------------------------------- ### Detect Latest Release in Go Source: https://context7.com/rhysd/go-github-selfupdate/llms.txt Checks for the latest release of a tool in a GitHub repository without performing an update. It retrieves release information such as version, download URL, and release notes, allowing for user prompts before an update. This function is useful for informing users about available updates. Requires the 'blang/semver' and 'rhysd/go-github-selfupdate' packages. ```go package main import ( "bufio" "fmt" "log" "os" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" ) const version = "1.2.3" func main() { latest, found, err := selfupdate.DetectLatest("owner/repo") if err != nil { log.Fatal("Error detecting version:", err) } if !found { fmt.Println("No release found") return } current := semver.MustParse(version) if latest.Version.LTE(current) { fmt.Println("Current version is up to date") return } fmt.Printf("New version %s available (current: %s)\n", latest.Version, current) fmt.Printf("Release URL: %s\n", latest.URL) fmt.Printf("Asset URL: %s\n", latest.AssetURL) fmt.Printf("Published: %s\n", latest.PublishedAt) fmt.Print("Do you want to update? (y/n): ") input, _ := bufio.NewReader(os.Stdin).ReadString('\n') if input == "y\n" { exe, _ := os.Executable() if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { log.Fatal("Update failed:", err) } fmt.Println("Updated successfully!") } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.