1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

style: move coolq.Version into internal/base

This commit is contained in:
wdvxdr 2021-09-24 23:28:09 +08:00
parent 87754111ce
commit f2ed46d6ce
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 21 additions and 18 deletions

View File

@ -27,7 +27,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X github.com/Mrs4s/go-cqhttp/coolq.Version=v{{.Version}}
- -s -w -X github.com/Mrs4s/go-cqhttp/internal/base.Version=v{{.Version}}
- id: win
env:
- CGO_ENABLED=0

View File

@ -10,7 +10,6 @@ import (
"path"
"path/filepath"
"runtime"
"runtime/debug"
"strconv"
"strings"
"time"
@ -23,21 +22,9 @@ import (
"github.com/tidwall/gjson"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/internal/base"
)
// Version go-cqhttp的版本信息在编译时使用ldflags进行覆盖
var Version = "unknown"
func init() {
if Version != "unknown" {
return
}
info, ok := debug.ReadBuildInfo()
if ok {
Version = info.Main.Version
}
}
// CQGetLoginInfo 获取登录号信息
//
// https://git.io/Jtz1I
@ -1388,8 +1375,8 @@ func (bot *CQBot) CQGetVersionInfo() global.MSG {
wd, _ := os.Getwd()
return OK(global.MSG{
"app_name": "go-cqhttp",
"app_version": Version,
"app_full_name": fmt.Sprintf("go-cqhttp-%s_%s_%s-%s", Version, runtime.GOOS, runtime.GOARCH, runtime.Version()),
"app_version": base.Version,
"app_full_name": fmt.Sprintf("go-cqhttp-%s_%s_%s-%s", base.Version, runtime.GOOS, runtime.GOARCH, runtime.Version()),
"protocol_version": "v11",
"coolq_directory": wd,
"coolq_edition": "pro",
@ -1399,7 +1386,7 @@ func (bot *CQBot) CQGetVersionInfo() global.MSG {
"plugin_build_configuration": "release",
"runtime_version": runtime.Version(),
"runtime_os": runtime.GOOS,
"version": Version,
"version": base.Version,
"protocol": func() int {
switch client.SystemDeviceInfo.Protocol {
case client.IPad:

16
internal/base/version.go Normal file
View File

@ -0,0 +1,16 @@
package base
import "runtime/debug"
// Version go-cqhttp的版本信息在编译时使用ldflags进行覆盖
var Version = "unknown"
func init() {
if Version != "unknown" {
return
}
info, ok := debug.ReadBuildInfo()
if ok {
Version = info.Main.Version
}
}