Refactor code related to getting current version

And set version in CertMagic for User-Agent purposes
This commit is contained in:
Matthew Holt
2019-06-28 19:28:28 -06:00
parent a4bdf249db
commit 31ab737bf2
5 changed files with 61 additions and 48 deletions

View File

@ -9,7 +9,6 @@ import (
"log"
"net"
"os"
"runtime/debug"
)
// Main executes the main function of the caddy command.
@ -66,23 +65,3 @@ func handlePingbackConn(conn net.Conn, expect []byte) error {
}
return nil
}
// getGoBuildModule returns the build info of Caddy
// from debug.BuildInfo (requires Go modules). If
// no version information is available, a non-nil
// value will still be returned, but with an
// unknown version.
func getGoBuildModule() *debug.Module {
bi, ok := debug.ReadBuildInfo()
if ok {
// The recommended way to build Caddy involves
// creating a separate main module, which
// TODO: track related Go issue: https://github.com/golang/go/issues/29228
for _, mod := range bi.Deps {
if mod.Path == "github.com/mholt/caddy" {
return mod
}
}
}
return &debug.Module{Version: "unknown"}
}