mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-23 23:32:30 -04:00
Refactor code related to getting current version
And set version in CertMagic for User-Agent purposes
This commit is contained in:
+9
-2
@@ -10,8 +10,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/caddy"
|
||||
"github.com/mholt/certmagic"
|
||||
"github.com/mitchellh/go-ps"
|
||||
)
|
||||
|
||||
@@ -126,6 +128,11 @@ func cmdRun() (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// set a fitting User-Agent for ACME requests
|
||||
goModule := caddy.GoModule()
|
||||
cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
|
||||
certmagic.UserAgent = "Caddy/" + cleanModVersion
|
||||
|
||||
// start the admin endpoint along with any initial config
|
||||
err := caddy.StartAdmin(config)
|
||||
if err != nil {
|
||||
@@ -180,10 +187,10 @@ func cmdStop() (int, error) {
|
||||
}
|
||||
|
||||
func cmdVersion() (int, error) {
|
||||
goModule := getGoBuildModule()
|
||||
goModule := caddy.GoModule()
|
||||
if goModule.Sum != "" {
|
||||
// a build with a known version will also have a checksum
|
||||
fmt.Printf("%s (%s)\n", goModule.Version, goModule.Sum)
|
||||
fmt.Printf("%s %s\n", goModule.Version, goModule.Sum)
|
||||
} else {
|
||||
fmt.Println(goModule.Version)
|
||||
}
|
||||
|
||||
-21
@@ -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"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user