diff --git a/.goreleaser.pre.yaml b/.goreleaser.pre.yaml index 682c7ec..661278e 100644 --- a/.goreleaser.pre.yaml +++ b/.goreleaser.pre.yaml @@ -12,7 +12,7 @@ builds: - arm - "386" ldflags: - - -s -w -X sub2sing-box/main.Version={{ .Version }} + - -s -w -X sub2sing-box/constant.Version={{ .Version }} flags: - -trimpath no_unique_dist_dir: true diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 2aea47c..9a6e416 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,7 +12,7 @@ builds: - arm - "386" ldflags: - - -s -w -X sub2sing-box/main.Version={{ .Version }} + - -s -w -X sub2sing-box/constant.Version={{ .Version }} flags: - -trimpath no_unique_dist_dir: true diff --git a/Dockerfile b/Dockerfile index 628043e..b03858d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN go mod download ARG version -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X sub2clash/config.Version=${version}" -o sub2sing-box main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X sub2sing-box/constant.Version=${version}" -o sub2sing-box main.go WORKDIR /app diff --git a/cmd/root.go b/cmd/root.go index 6d8c1e7..ebef5cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,3 @@ import ( ) var RootCmd = &cobra.Command{} - -func SetVersion(version string) { - RootCmd.Version = version -} diff --git a/cmd/version.go b/cmd/version.go index 2bb8dc2..608c9ce 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "sub2sing-box/constant" "github.com/spf13/cobra" ) @@ -11,7 +12,7 @@ var versionCmd = &cobra.Command{ Short: "Print version", Long: "Print version", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("version: " + RootCmd.Version) + fmt.Println("version: " + constant.Version) }, } diff --git a/constant/version.go b/constant/version.go new file mode 100644 index 0000000..c8b5168 --- /dev/null +++ b/constant/version.go @@ -0,0 +1,3 @@ +package constant + +var Version = "dev" diff --git a/main.go b/main.go index 98cf883..408dbce 100644 --- a/main.go +++ b/main.go @@ -5,13 +5,6 @@ import ( "sub2sing-box/cmd" ) -var Version string - -func init() { - Version = "dev" - cmd.SetVersion(Version) -} - func main() { if err := cmd.RootCmd.Execute(); err != nil { fmt.Println(err)