mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 11:29:37 +08:00
update: version
This commit is contained in:
@@ -28,6 +28,9 @@ WORKDIR /app
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
|
# 先复制VERSION文件,确保构建时能正确读取版本号
|
||||||
|
COPY VERSION ./
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func GetSystemInfo(c *gin.Context) {
|
|||||||
SuccessResponse(c, gin.H{
|
SuccessResponse(c, gin.H{
|
||||||
"uptime": time.Since(startTime).String(),
|
"uptime": time.Since(startTime).String(),
|
||||||
"start_time": startTime.Format("2006-01-02 15:04:05"),
|
"start_time": startTime.Format("2006-01-02 15:04:05"),
|
||||||
"version": "1.0.0",
|
"version": utils.Version,
|
||||||
"environment": gin.H{
|
"environment": gin.H{
|
||||||
"gin_mode": gin.Mode(),
|
"gin_mode": gin.Mode(),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -72,8 +73,8 @@ func CheckUpdate(c *gin.Context) {
|
|||||||
// 从GitHub API获取最新版本信息
|
// 从GitHub API获取最新版本信息
|
||||||
latestVersion, err := getLatestVersionFromGitHub()
|
latestVersion, err := getLatestVersionFromGitHub()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 如果GitHub API失败,使用模拟数据
|
// 如果GitHub API失败,使用当前版本作为最新版本
|
||||||
latestVersion = "1.0.0"
|
latestVersion = currentVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
hasUpdate := utils.IsVersionNewer(latestVersion, currentVersion)
|
hasUpdate := utils.IsVersionNewer(latestVersion, currentVersion)
|
||||||
@@ -96,10 +97,25 @@ func CheckUpdate(c *gin.Context) {
|
|||||||
|
|
||||||
// getLatestVersionFromGitHub 从GitHub获取最新版本
|
// getLatestVersionFromGitHub 从GitHub获取最新版本
|
||||||
func getLatestVersionFromGitHub() (string, error) {
|
func getLatestVersionFromGitHub() (string, error) {
|
||||||
// 使用GitHub API获取最新Release
|
// 首先尝试从VERSION文件URL获取最新版本
|
||||||
|
versionURL := "https://raw.githubusercontent.com/ctwj/urldb/refs/heads/main/VERSION"
|
||||||
|
|
||||||
|
resp, err := http.Get(versionURL)
|
||||||
|
if err == nil && resp.StatusCode == http.StatusOK {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err == nil {
|
||||||
|
version := strings.TrimSpace(string(body))
|
||||||
|
if version != "" {
|
||||||
|
return version, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果VERSION文件获取失败,尝试GitHub API获取最新Release
|
||||||
url := "https://api.github.com/repos/ctwj/urldb/releases/latest"
|
url := "https://api.github.com/repos/ctwj/urldb/releases/latest"
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err = http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user