Files
anchorage/internal/cmd/version.go
William Gill 12bf35caf8 anchorage v1.0 initial tree
Greenfield Go multi-tenant IPFS Pinning Service wire-compatible with the
IPFS Pinning Services API spec. Paired 1:1 with Kubo over localhost RPC,
clustered via embedded NATS JetStream, Postgres source-of-truth with
RLS-enforced tenancy, Fiber + huma v2 for the HTTP surface, Authentik
OIDC for session login with kid-rotated HS256 JWT API tokens.

Feature-complete against the 22-milestone build plan, including the
ship-it v1.0 gap items:

  * admin CLIs: drain/uncordon, maintenance, mint-token, rotate-key,
    prune-denylist, rebalance --dry-run, cache-stats, cluster-presences
  * TTL leader election via NATS KV, fence tokens, JetStream dedup
  * rebalancer (plan/apply split), reconciler, requeue sweeper
  * ristretto caches with NATS-backed cross-node invalidation
    (placements live-nodes + token denylist)
  * maintenance watchdog for stuck cluster-pause flag
  * Prometheus /metrics with CIDR ACL, HTTP/pin/scheduler/cache gauges
  * rate limiting: session (10/min) + anonymous global (120/min)
  * integration tests: rebalance, refcount multi-org, RLS belt
  * goreleaser (tar + deb/rpm/apk + Alpine Docker) targeting Gitea

Stack: Cobra/Viper, Fiber v2 + huma v2, embedded NATS JetStream,
pgx/sqlc/golang-migrate, ristretto, TypeID, prometheus/client_golang,
testcontainers-go.
2026-04-16 18:13:36 -05:00

70 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"runtime"
"runtime/debug"
"github.com/spf13/cobra"
)
// Build metadata — overridden via -ldflags at release time.
//
// go build -ldflags "-X anchorage/internal/cmd.version=v0.1.0 -X anchorage/internal/cmd.commit=<sha> -X anchorage/internal/cmd.date=<iso8601>"
var (
version = "dev"
commit = ""
date = ""
)
// newVersionCmd prints build metadata and exits.
//
// Falls back to debug.ReadBuildInfo() for commit/date so `go install` and
// `go run` produce useful output even without ldflags.
func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print anchorage version and build metadata",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
v, c, d := resolveBuildInfo()
out := cmd.OutOrStdout()
fmt.Fprintf(out, "anchorage %s\n", v)
if c != "" {
fmt.Fprintf(out, " commit: %s\n", c)
}
if d != "" {
fmt.Fprintf(out, " built: %s\n", d)
}
fmt.Fprintf(out, " runtime: %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
return nil
},
}
}
// resolveBuildInfo prefers ldflag-injected values and falls back to the
// module's embedded vcs info when unset.
func resolveBuildInfo() (v, c, d string) {
v, c, d = version, commit, date
if c != "" && d != "" {
return
}
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
if c == "" {
c = s.Value
}
case "vcs.time":
if d == "" {
d = s.Value
}
}
}
return
}