This directory contains example programs demonstrating how to use the github-release-version-checker library in your own Go applications.
All examples require a GitHub token to avoid rate limiting:
export GITHUB_TOKEN="your_github_token_here"Each example is a standalone Go program. To run an example:
cd examples/basic
go run main.goDemonstrates the fundamental usage of the library:
- Creating a GitHub client
- Setting up a days-based policy
- Analysing a version
- Interpreting results
cd examples/basic
go run main.goShows how to use version-based policies (e.g., for Kubernetes):
- Creating a version-based policy (support N minor versions)
- Checking if a version is within the support window
- Handling version-based expiry
cd examples/version-based-policy
go run main.goDemonstrates checking any GitHub repository:
- Parameterized owner/repo/version
- Disabling cache for custom repos
- Displaying newer releases
cd examples/custom-repository
go run main.go hashicorp terraform 1.5.0Shows how to use the built-in JSON marshalling:
- Encoding analysis results as JSON
- Error handling with JSON output
- Structured data for automation
cd examples/json-output
go run main.goTo use this library in your own project:
go get github.com/nickromney-org/github-release-version-checkerThen import the packages you need:
import (
"github.com/nickromney-org/github-release-version-checker/pkg/checker"
"github.com/nickromney-org/github-release-version-checker/pkg/client"
"github.com/nickromney-org/github-release-version-checker/pkg/policy"
)// Create a GitHub client
ghClient := client.NewClient(token, owner, repo)
// Fetch releases
releases, err := ghClient.GetAllReleases(ctx)
recentReleases, err := ghClient.GetRecentReleases(ctx, 5)
latest, err := ghClient.GetLatestRelease(ctx)// Days-based policy (e.g., GitHub Actions runners)
daysPolicy := policy.NewDaysPolicy(criticalDays, maxDays)
// Version-based policy (e.g., Kubernetes)
versionPolicy := policy.NewVersionsPolicy(maxMinorVersionsBehind)// Create checker with policy
versionChecker := checker.NewCheckerWithPolicy(ghClient, checker.Config{
CriticalAgeDays: 12,
MaxAgeDays: 30,
NoCache: false,
}, pol)
// Analyse a version
analysis, err := versionChecker.Analyse(ctx, "2.328.0")
// Check status
switch analysis.Status() {
case checker.StatusCurrent:
// Up to date
case checker.StatusWarning:
// Behind but within policy
case checker.StatusCritical:
// Approaching expiry
case checker.StatusExpired:
// Beyond policy threshold
}- Main README - Full project documentation
- API Documentation - Go package documentation