semver

A fast, spec-compliant Go library for parsing, comparing, and sorting semantic versions with npm-style range constraints.

Library
Go
vv3.5.0
1,431stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture78
Code Quality92
Innovation74
Learning Curve65

Masterminds/semver is a pure Go package for working with Semantic Versions: parsing version strings, sorting them, and checking whether they satisfy a constraint expression. It supports both strict RFC-compliant parsing via StrictNewVersion and a coercive NewVersion that tolerates partial or non-compliant version strings (like CalVer-style values with leading zeros), making it useful for real-world version strings that don’t perfectly follow the spec.

Constraint checking follows the range conventions popularized by npm and Cargo rather than a from-scratch design, supporting comparison operators (=, !=, >, <, >=, <=), hyphen ranges, wildcards (x, X, *), and the tilde (~) and caret (^) shorthand operators for patch- and major-level ranges. The library is widely used as the versioning engine inside dependency-management and package-manager tooling across the Go ecosystem, including Helm and dep.

What You Get

  • A Version type with strict (StrictNewVersion) and coercive (NewVersion) parsing
  • A Constraints type supporting =, !=, >, <, >=, <=, hyphen ranges, wildcards, ~, and ^ operators
  • A Collection type implementing sort.Interface for sorting slices of versions
  • JSON, text, and database/sql (Scan/Value) marshaling support on Version
  • Safe increment helpers (IncMajorE, IncMinorE, IncPatchE) that return errors on uint64 overflow instead of panicking

Common Use Cases

  • Validating that a dependency’s installed version satisfies a version range declared in a manifest file
  • Sorting a list of Git tags or release versions into semantic order
  • Implementing update-policy logic (e.g. “only auto-upgrade patch releases”) using tilde/caret constraints
  • Storing and retrieving parsed version values directly from a SQL database column

Under The Hood

Architecture The package is a single flat semver package with no internal layering: version.go defines the Version type and its parsing/comparison/marshaling methods, constraints.go defines Constraints/constraint and the regex-driven range grammar (rewriteRange, findConstraintRegex, validConstraintRegex), and collection.go is a small adapter implementing sort.Interface. There is no dependency injection or multi-layer design because the surface area is intentionally narrow: parse a string into a Version, evaluate a Constraints against it. Data flows one direction — string in, typed struct out, boolean/int out of comparisons — with no external I/O and no state beyond two package-level regexes compiled once in init(). Because the type is small and consumers only ever touch exported methods, changes to the core struct stay contained to this one file.

Tech Stack go.mod declares the module for Go 1.21 with zero third-party dependencies — the implementation relies solely on the standard library (regexp, strings, strconv, encoding/json, database/sql/driver). Build tooling is a plain Makefile wrapping go test/go vet, CI runs through GitHub Actions (test, golangci-lint, CodeQL, and a native Go fuzz job) against current Go releases, and golangci-lint v2 is configured with a strict linter set including gosec, gocyclo, errcheck, staticcheck, revive, and unparam. As a dependency-free leaf library it’s built to be vendored into other Go binaries — notably Helm and dep — and it implements database/sql/driver.Valuer/Scanner purely so consuming applications can persist Version values without extra glue code.

Code Quality Testing is extensive: version_test.go and constraints_test.go each carry roughly 1,200 lines of table-driven tests covering parsing edge cases, comparison ordering, and marshaling, alongside a dedicated benchmark suite and a CI fuzz job exercising the parser continuously. Error handling is idiomatic Go — exported sentinel errors (ErrInvalidSemVer, ErrEmptyString, ErrIncrementOverflow) are returned rather than panicking, and ...E-suffixed increment variants were added specifically to replace silent-overflow behavior with explicit, wrappable errors. Naming is consistent and idiomatic, the codebase is gofmt/goimports-formatted, and CI enforces a strict golangci-lint v2 profile plus CodeQL static analysis. Bounded-input constants (MaxVersionLen, MaxConstraintLen, MaxConstraintGroups) show deliberate hardening against oversized or adversarial input.

API Design The public API is deliberately minimal: NewVersion offers permissive coercion while StrictNewVersion enforces spec compliance, letting callers opt into exactly the leniency they need, and MustParse gives a panic-on-error convenience for tests and constants. Constraint syntax intentionally mirrors what developers already know from npm and Cargo (~, ^, hyphen ranges, wildcards) instead of inventing new range grammar, lowering the learning curve for anyone coming from another ecosystem’s version ranges. Zero-boilerplate integration is a deliberate goal — Version implements fmt.Stringer, JSON, text, and SQL driver interfaces so it drops directly into JSON APIs, config structs, and database columns without adapter code, and package-level toggles (CoerceNewVersion, DetailedNewVersionErrors) let callers tune strictness and performance trade-offs globally.

Used by 13 apps in this directory

Rust
65%
Apache 2.0

agentgateway

AI Development · Developer Tools

4,640

An open source AI-native proxy that secures, observes, and governs agent-to-LLM, agent-to-tool, and agent-to-agent communication through MCP, A2A, and unified LLM routing.

View details
87
Repo Health
82
Technical
71
Dependency
Built with
Rust65%
Go23%
Updated 3 days ago
Go
60%
Apache 2.0

Apache Answer

Community

15,658

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
84
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Go
92%
AGPL 3.0

Cozy Stack

File Storage · Productivity

1,270

Self-hosted personal cloud platform that unifies your files, apps, and devices in one private space you fully control.

View details
94
Repo Health
77
Technical
67
Dependency
Built with
Go92%
Updated 2 days ago
Shell
48%
MIT

Dokku

Devops · Hosting Control Panel

32,114

The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.

View details
93
Repo Health
85
Technical
71
Dependency
Built with
Shell48%
Go48%
Updated today
Go
89%
Apache 2.0

Glasskube

Developer Tools · Devops

3,493

A next-generation Kubernetes package manager with a GUI, CLI, and native GitOps integration that makes deploying cluster workloads 20x faster than Helm.

View details
55
Repo Health
74
Technical
76
Dependency
Built with
Go89%
Updated 2 months ago
Go
68%
MIT

Gogs

Developer Tools

47,783

The painless self-hosted Git service that runs on anything from a Raspberry Pi to a $5 cloud droplet, delivering GitHub-like workflows as a single Go binary.

View details
96
Repo Health
79
Technical
72
Dependency
Built with
Go68%
Go Template16%
TypeScript10%
Updated 4 days ago
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
61%
Apache 2.0

Harness Open Source

Developer Tools · Devops · Code Editors

38,169

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
89
Repo Health
79
Technical
64
Dependency
Built with
Go61%
TypeScript34%
Updated 2 days ago
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,812

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
Go84%
PLpgSQL11%
Updated today

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