package main import ( "runtime/debug" httpapi "git.kmalloc.org/squid/sonda/internal/api/http" ) // shortRevision is how many characters of the commit the app shows. const shortRevision = 7 // revision reads the commit the binary was built from, and whether the files had changes that were not committed. // Go records both in a build made inside a git checkout; a build without them (a copy of the sources, or // -buildvcs=false) has no revision. func revision(info *debug.BuildInfo) (rev string, modified bool) { if info == nil { return "", false } for _, s := range info.Settings { switch s.Key { case "vcs.revision": rev = s.Value if len(rev) > shortRevision { rev = rev[:shortRevision] } case "vcs.modified": modified = s.Value == "true" } } if rev == "" { modified = false } return rev, modified } // build says which Sonda this is, for the signed-in users to see. func build() httpapi.Build { info, _ := debug.ReadBuildInfo() rev, modified := revision(info) return httpapi.Build{Version: version, Revision: rev, Modified: modified} }