fix bug:重构版本信息的位置解决包引用环路问题

This commit is contained in:
tsosunchia
2023-05-30 14:55:47 +08:00
parent 288aee254f
commit 4e5cd2d053
5 changed files with 22 additions and 20 deletions

View File

@@ -26,15 +26,15 @@ for pl in ${PLATFORMS}; do
echo "build => ${TARGET}"
if [ "${DEBUG_MODE}" == "debug" ]; then
go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
-ldflags "-X 'github.com/xgadget-lab/nexttrace/config.Version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/config.BuildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/config.CommitID=${COMMIT_SHA1}'\
-w -s"
else
go build -trimpath -o ${TARGET} \
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
-ldflags "-X 'github.com/xgadget-lab/nexttrace/config.Version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/config.BuildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/config.CommitID=${COMMIT_SHA1}'\
-w -s"
fi
done

View File

@@ -131,9 +131,9 @@ jobs:
- name: Build
run: |
go build -trimpath -o dist/${ASSET_NAME} \
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
-ldflags "-X 'github.com/xgadget-lab/nexttrace/config.Version=${BUILD_VERSION}' \
-X 'github.com/xgadget-lab/nexttrace/config.BuildDate=${BUILD_DATE}' \
-X 'github.com/xgadget-lab/nexttrace/config.CommitID=${COMMIT_SHA1}'\
-w -s"
- name: Upload files to Artifacts
uses: actions/upload-artifact@v3

5
config/basic.go Normal file
View File

@@ -0,0 +1,5 @@
package config
var Version = "v0.0.0.alpha"
var BuildDate = ""
var CommitID = ""

View File

@@ -2,19 +2,16 @@ package printer
import (
"fmt"
"github.com/xgadget-lab/nexttrace/config"
"github.com/xgadget-lab/nexttrace/trace"
"net"
"github.com/fatih/color"
)
var version = "v0.0.0.alpha"
var buildDate = ""
var commitID = ""
func GetVersion() string {
return version
}
var version = config.Version
var buildDate = config.BuildDate
var commitID = config.CommitID
func Version() {
fmt.Fprintf(color.Output, "%s %s %s %s\n",

View File

@@ -3,7 +3,8 @@ package wshandle
import (
"crypto/tls"
"fmt"
"github.com/xgadget-lab/nexttrace/printer"
"github.com/xgadget-lab/nexttrace/config"
"github.com/xgadget-lab/nexttrace/util"
"log"
"net"
"net/http"
@@ -16,7 +17,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/xgadget-lab/nexttrace/util"
)
type WsConn struct {
@@ -123,7 +123,7 @@ func (c *WsConn) recreateWsConn() {
// log.Printf("connecting to %s", u.String())
requestHeader := http.Header{
"Host": []string{host},
"User-Agent": []string{fmt.Sprintf("NextTrace %s/%s/%s", printer.GetVersion(), runtime.GOOS, runtime.GOARCH)},
"User-Agent": []string{fmt.Sprintf("NextTrace %s/%s/%s", config.Version, runtime.GOOS, runtime.GOARCH)},
}
dialer := websocket.DefaultDialer
dialer.TLSClientConfig = &tls.Config{
@@ -182,7 +182,7 @@ func createWsConn() *WsConn {
// 判断是否是一个 IP
requestHeader := http.Header{
"Host": []string{host},
"User-Agent": []string{fmt.Sprintf("NextTrace %s/%s/%s", printer.GetVersion(), runtime.GOOS, runtime.GOARCH)},
"User-Agent": []string{fmt.Sprintf("NextTrace %s/%s/%s", config.Version, runtime.GOOS, runtime.GOARCH)},
}
dialer := websocket.DefaultDialer
dialer.TLSClientConfig = &tls.Config{