From 31ab737bf26deb9315ffedf99a8bb7d43f620700 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 28 Jun 2019 19:28:28 -0600 Subject: Refactor code related to getting current version And set version in CertMagic for User-Agent purposes --- cmd/commands.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'cmd/commands.go') 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) } -- cgit v1.2.3