From 147b8a47df8dd0d6239261b4845123096fbea552 Mon Sep 17 00:00:00 2001 From: liruichen Date: Fri, 25 Aug 2023 18:47:10 +0800 Subject: [PATCH] feat: log version --- cmd/version.go | 6 +++--- hack/release.sh | 2 +- pkg/server/server.go | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 37f1b6e..3b57cef 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/cobra" ) -var version = "unstable" +var Version = "unstable" var versionCmd = &cobra.Command{ Use: "version", @@ -31,13 +31,13 @@ goc version `, Run: func(cmd *cobra.Command, args []string) { // if it is "Unstable", means user build local or with go get - if version == "unstable" { + if Version == "unstable" { if info, ok := debug.ReadBuildInfo(); ok { fmt.Println(info.Main.Version) } } else { // otherwise the value is injected in CI - fmt.Println(version) + fmt.Println(Version) } }, } diff --git a/hack/release.sh b/hack/release.sh index 1ce3b69..8bfe321 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -10,7 +10,7 @@ RELEASE_VERSION=$(echo $EVENT_DATA | jq -r .release.tag_name) PROJECT_NAME=$(basename $GITHUB_REPOSITORY) NAME="${NAME:-${PROJECT_NAME}-${RELEASE_VERSION}}-${GOOS}-${GOARCH}" -CGO_ENABLED=0 go build -ldflags "-X 'github.com/RickLeee/goc-v2/cmd.version=${RELEASE_VERSION}'" . +CGO_ENABLED=0 go build -ldflags "-X 'github.com/RickLeee/goc-v2/cmd.Version=${RELEASE_VERSION}'" . ARCHIVE=tmp.tar.gz FILE_LIST=goc diff --git a/pkg/server/server.go b/pkg/server/server.go index 6cd1079..23957e4 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -17,6 +17,7 @@ import ( "crypto/sha256" "encoding/json" "fmt" + "github.com/qiniu/goc/v2/cmd" "math/rand" "net/http" "net/rpc" @@ -89,7 +90,7 @@ func (agent *gocCoveredAgent) closeConnection() { } } -// api 客户端,不是 agent +// api 客户端,不是 agent type gocWatchClient struct { ws *websocket.Conn exitCh chan int @@ -130,7 +131,7 @@ func RunGocServerUntilExit(host string, s store.Store) error { } go gs.watchLoop() - + log.Infof("version: %v", cmd.Version) return r.Run(host) }