Add main.Version
This commit is contained in:
parent
347823b0bd
commit
2aa043b5fc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
tglistbot*
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
VERSION = $(shell git describe --tags --abbrev=0)
|
||||
|
||||
build_release:
|
||||
CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(VERSION)" -o tglistbot-$(VERSION)
|
||||
|
||||
release_check:
|
||||
go list -m go.balki.me/tglistbot@$(VERSION)
|
||||
|
9
main.go
9
main.go
@ -22,6 +22,8 @@ import (
|
||||
"go.balki.me/tglistbot/glist"
|
||||
)
|
||||
|
||||
// Version will be set from build commandline
|
||||
var Version string
|
||||
var apiToken string
|
||||
|
||||
func main() {
|
||||
@ -61,7 +63,10 @@ func main() {
|
||||
|
||||
glist.DataPath = dataPath
|
||||
|
||||
commit := func() string {
|
||||
version := func() string {
|
||||
if Version != "" {
|
||||
return Version
|
||||
}
|
||||
if bi, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, s := range bi.Settings {
|
||||
if s.Key == "vcs.revision" {
|
||||
@ -79,7 +84,7 @@ func main() {
|
||||
return fmt.Sprintf("port: %v", port)
|
||||
}()
|
||||
|
||||
log.Printf("List bot (%s) starting with datapath: %q, %s\n", commit, dataPath, listeningOn)
|
||||
log.Printf("List bot (%s) starting with datapath: %q, %s\n", version, dataPath, listeningOn)
|
||||
|
||||
var chats sync.Map
|
||||
if err := loadData(dataPath, &chats); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user