summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-06-28 19:28:28 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-06-28 19:28:28 -0600
commit31ab737bf26deb9315ffedf99a8bb7d43f620700 (patch)
treebec4c5f0ac1b6b5387c2f0d179276fe340b57539 /cmd
parenta4bdf249dbfb0f35e0a35dad6a38db371b126800 (diff)
Refactor code related to getting current version
And set version in CertMagic for User-Agent purposes
Diffstat (limited to 'cmd')
-rw-r--r--cmd/commands.go11
-rw-r--r--cmd/main.go21
2 files changed, 9 insertions, 23 deletions
diff --git a/cmd/commands.go b/cmd/commands.go
index 4745af7..3f866d1 100644
--- a/cmd/commands.go
+++ b/cmd/commands.go
@@ -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)
}
diff --git a/cmd/main.go b/cmd/main.go
index b9baf84..9cd2ae0 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -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"}
-}