feat: log version

This commit is contained in:
liruichen 2023-08-25 18:47:10 +08:00
parent d1708d550e
commit 147b8a47df
3 changed files with 7 additions and 6 deletions

View File

@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var version = "unstable" var Version = "unstable"
var versionCmd = &cobra.Command{ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
@ -31,13 +31,13 @@ goc version
`, `,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// if it is "Unstable", means user build local or with go get // if it is "Unstable", means user build local or with go get
if version == "unstable" { if Version == "unstable" {
if info, ok := debug.ReadBuildInfo(); ok { if info, ok := debug.ReadBuildInfo(); ok {
fmt.Println(info.Main.Version) fmt.Println(info.Main.Version)
} }
} else { } else {
// otherwise the value is injected in CI // otherwise the value is injected in CI
fmt.Println(version) fmt.Println(Version)
} }
}, },
} }

View File

@ -10,7 +10,7 @@ RELEASE_VERSION=$(echo $EVENT_DATA | jq -r .release.tag_name)
PROJECT_NAME=$(basename $GITHUB_REPOSITORY) PROJECT_NAME=$(basename $GITHUB_REPOSITORY)
NAME="${NAME:-${PROJECT_NAME}-${RELEASE_VERSION}}-${GOOS}-${GOARCH}" 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 ARCHIVE=tmp.tar.gz
FILE_LIST=goc FILE_LIST=goc

View File

@ -17,6 +17,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/qiniu/goc/v2/cmd"
"math/rand" "math/rand"
"net/http" "net/http"
"net/rpc" "net/rpc"
@ -89,7 +90,7 @@ func (agent *gocCoveredAgent) closeConnection() {
} }
} }
// api 客户端,不是 agent // api 客户端,不是 agent
type gocWatchClient struct { type gocWatchClient struct {
ws *websocket.Conn ws *websocket.Conn
exitCh chan int exitCh chan int
@ -130,7 +131,7 @@ func RunGocServerUntilExit(host string, s store.Store) error {
} }
go gs.watchLoop() go gs.watchLoop()
log.Infof("version: %v", cmd.Version)
return r.Run(host) return r.Run(host)
} }