go-version

A Go library for parsing, comparing, sorting, and constraint-checking semantic versions, built by HashiCorp for tools like Terraform and Vault.

Library
Go
vv1.9.0
1,771stars
Mozilla Public License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
74/100Good
Development Activity72
Maintenance48
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality88
Innovation55
Learning Curve85

go-version is HashiCorp’s Go library for working with software version strings. It parses version text into a structured Version type, compares versions correctly (including prerelease and metadata segments per SemVer rules), sorts collections of versions, and checks a version against one or more constraint expressions such as >= 1.0, < 2.0 or the pessimistic ~> 1.2 operator.

The library grew out of HashiCorp’s own tooling needs — it underpins version handling in projects like Terraform and Vault — and stays deliberately small: a handful of files, zero runtime dependencies, and a stable, well-documented public API. Recent releases added an opt-in WithPrefix option so callers can parse versions carrying a known prefix (like deployment-v1.2.3) without pre-processing the string themselves.

Because it implements encoding.TextMarshaler/TextUnmarshaler and database/sql’s Scanner/Valuer interfaces, Version values drop directly into JSON, YAML, and database columns without extra glue code, which is a big part of why it’s become a common building block anywhere a Go project needs to reason about version numbers.

What You Get

  • A Version type with NewVersion/NewSemver parsers, plus Compare, LessThan, GreaterThan, Equal, and related comparison methods
  • A Constraint/Constraints type parsed from strings like >= 1.0, < 1.4 with Check(v) to test a version against them
  • Operators covering equality, inequality, ordering, and the pessimistic ~> (approximately-greater-than) operator
  • A Collection type implementing sort.Interface so slices of versions can be sorted with the standard library’s sort package
  • encoding.TextMarshaler/TextUnmarshaler and database/sql Scanner/Valuer implementations for drop-in JSON and database use
  • An opt-in WithPrefix option (added in v1.9.0) for parsing versions that carry a known non-numeric prefix

Common Use Cases

  • Validating that a user- or config-supplied version string satisfies a required range before running an operation
  • Sorting a list of release tags or module versions into correct semantic order
  • Implementing update-checkers or dependency resolvers that need accurate version comparison, including prerelease handling
  • Storing and retrieving version values from a SQL database column via the Scanner/Valuer interfaces
  • Parsing versions with custom deployment or component prefixes without manual string trimming

Under The Hood

Architecture The library is deliberately flat: four source files (version.go, constraint.go, version_collection.go, plus a small options block) with no internal package boundaries. Version is the core data type, storing parsed segments, prerelease, metadata, original string, and an optional prefix; parsing happens once through a shared newVersion helper driven by lazily-compiled regular expressions (versionRegexpOnce/semverRegexpOnce via sync.Once) so the cost of building the pattern is paid only on first use. Constraint wraps a Version plus an operator function (constraintFunc), and NewConstraint splits a comma-separated string into a Constraints slice, each element independently parsed by parseSingle. Collection is a thin adapter implementing sort.Interface over []*Version, delegating ordering to Version.LessThan. There is no dependency injection or layering to speak of — the design is a single cohesive value type with methods, which is appropriate for a parsing/comparison library; changing the core Compare logic would ripple into every constraint operator function since they all call Compare/LessThan under the hood.

Tech Stack Pure standard-library Go: regexp for pattern matching, strconv for numeric parsing, strings for splitting/trimming, sort for the Collection sort interface, sync for one-time regex compilation, and database/sql/driver to implement Scanner/Valuer. The go.mod declares go 1.16 as the minimum version and lists zero external dependencies — nothing to vendor, no supply-chain surface beyond Go itself. Build tooling is a small Makefile plus a GitHub Actions workflow (go-tests.yml) that runs the test suite and a copywrite.yml workflow that checks license headers, HashiCorp’s standard OSS repo hygiene setup.

Code Quality Testing is thorough relative to the codebase size: roughly 1,220 lines across three _test.go files against about 800 lines of implementation, with 31 top-level Test* functions covering version parsing edge cases, prerelease/metadata comparison, constraint operators (including the pessimistic ~> operator and prerelease-aware constraint matching), and collection sorting. Error handling is explicit and idiomatic — parsing functions return (*Version, error) / (*Constraint, error) rather than panicking, with a separate Must/MustConstraints panic-wrapper offered for callers who want the shortcut. Naming is consistent and exported symbols carry full doc comments suitable for pkg.go.dev. CI runs the test suite on every push/PR via GitHub Actions, and a license-header check (copywrite) enforces consistency across files.

What Makes It Unique The library goes beyond strict SemVer by accepting a wider, more permissive version grammar (VersionRegexpRaw) alongside a strict SemverRegexpRaw used by NewSemver, which lets it parse the messier version strings seen in the wild (Terraform providers, Vault plugins, arbitrary CLI tools) while still offering a strict-mode entry point when needed. Its pessimistic ~> constraint operator mirrors Bundler/RubyGems conventions, a comparison idiom not built into Go’s standard library or most peer version-parsing packages. The newer WithPrefix option is a targeted, narrowly-scoped addition rather than general prefix-stripping magic — it validates the prefix is actually present before stripping it, and keeps the parsed prefix retrievable via Prefix(), which is a deliberate API design choice for correctness-conscious callers. Combined with native database and text-marshaling interface support, it is more of an infrastructure-tooling foundation than a generic SemVer parser.

Used by 13 apps in this directory

Go
75%
AGPL 3.0

Coder

Devops · Developer Tools · Code Editors

14,299

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
93
Repo Health
90
Technical
69
Dependency
Built with
Go75%
TypeScript23%
Updated today
Go
59%
Apache 2.0

Cog

AI Development · Devops · Developer Tools

9,464

An open-source CLI that packages machine learning models into standard, production-ready Docker containers — no Dockerfile wrangling, no CUDA version hell.

View details
90
Repo Health
88
Technical
69
Dependency
Built with
Go59%
Rust17%
HTML13%
Updated 4 days ago
Go
83%
MIT

Gitea

Devops · Developer Tools · Project Management

57,677

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
Go83%
Updated today
TypeScript
49%
AGPL 3.0

Grafana

Monitoring · Analytics

76,498

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
65
Dependency
Built with
TypeScript49%
Go45%
Updated today
Go
97%
Apache 2.0

infracost

Devops · Developer Tools

12,499

Infracost shows cloud cost estimates for Terraform, CloudFormation, and AWS CDK before you deploy — in your terminal, editor, AI coding agent, and pull requests.

View details
79
Repo Health
78
Technical
68
Dependency
Built with
Go97%
Updated 6 days ago
Go
94%
Other

NetBird

Security

28,735

Replace your VPN with a zero-trust WireGuard overlay network that auto-connects devices, enforces SSO and posture checks, and deploys in under 5 minutes.

View details
92
Repo Health
82
Technical
66
Dependency
Built with
Go94%
Updated today
Go
96%
Other

Netmaker

Automation · Security

11,771

Automate secure WireGuard mesh networks from homelab to enterprise scale without manual configuration.

View details
92
Repo Health
79
Technical
71
Dependency
Built with
Go96%
Updated today
Go
98%
Apache 2.0

Nightingale

Monitoring

13,272

Open-source alerting engine that connects to any time-series or log data source and routes alarms to 20+ notification channels with AI-assisted triage.

View details
96
Repo Health
77
Technical
68
Dependency
Built with
Go98%
Updated today
Go
39%
Apache 2.0

Rill

Analytics · Data Engineering

2,853

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
87
Repo Health
88
Technical
66
Dependency
Built with
Go39%
TypeScript37%
Svelte22%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search