Skip to content

Commit 6ce03e9

Browse files
committed
feat(backend): build info
Signed-off-by: Me0wo <152751263+Sn0wo2@users.noreply.github.com>
1 parent e5f614d commit 6ce03e9

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

main.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56
"os/signal"
67
"runtime"
78
"runtime/debug"
89
"syscall"
10+
"time"
911

1012
"github.com/Sn0wo2/QuickNote/internal/listener"
1113
"github.com/Sn0wo2/QuickNote/internal/router"
@@ -14,6 +16,7 @@ import (
1416
"github.com/Sn0wo2/QuickNote/pkg/database/orm"
1517
"github.com/Sn0wo2/QuickNote/pkg/database/table"
1618
"github.com/Sn0wo2/QuickNote/pkg/log"
19+
"github.com/Sn0wo2/QuickNote/pkg/version"
1720
"github.com/gofiber/fiber/v2"
1821
"github.com/joho/godotenv"
1922
"go.uber.org/zap"
@@ -25,30 +28,30 @@ func init() {
2528
debug.SetGCPercent(50)
2629

2730
_ = godotenv.Load()
28-
}
2931

30-
func main() {
3132
err := config.Init()
3233
if err != nil {
3334
// log not init~
3435
panic(err)
3536
}
3637

3738
log.Init()
39+
}
3840

41+
func main() {
3942
defer func() {
4043
_ = log.Instance.Sync()
4144
}()
4245

43-
err = orm.Init(config.Instance.Database.Type, config.Instance.Database.URL)
44-
if err != nil {
46+
log.Instance.Info("Starting QuickNote...", zap.String("version", fmt.Sprintf("%s-%s(%s)", version.GetVersion(), version.GetCommit(), version.GetDateTime().Format(time.DateTime))))
47+
48+
if err := orm.Init(config.Instance.Database.Type, config.Instance.Database.URL); err != nil {
4549
log.Instance.Fatal("Failed to initialize database",
4650
zap.Error(err),
4751
)
4852
}
4953

50-
err = table.Init()
51-
if err != nil {
54+
if err := table.Init(); err != nil {
5255
log.Instance.Fatal("Failed to initialize tables",
5356
zap.Error(err),
5457
)
@@ -68,7 +71,7 @@ func main() {
6871
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
6972

7073
go func() {
71-
if err = listener.Start(app); err != nil {
74+
if err := listener.Start(app); err != nil {
7275
log.Instance.Fatal("Server failed to start",
7376
zap.Error(err),
7477
)
@@ -77,7 +80,7 @@ func main() {
7780

7881
<-shutdownChan
7982

80-
if err = app.Shutdown(); err != nil {
83+
if err := app.Shutdown(); err != nil {
8184
log.Instance.Error("Server shutdown error",
8285
zap.Error(err),
8386
)

pkg/version/version.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package version
2+
3+
import (
4+
"time"
5+
)
6+
7+
var version = "unknown"
8+
var commit = "unknown"
9+
var date = "unknown"
10+
11+
func GetVersion() string {
12+
return version
13+
}
14+
15+
func GetCommit() string {
16+
return commit
17+
}
18+
19+
func GetDate() string {
20+
return date
21+
}
22+
23+
func GetDateTime() time.Time {
24+
t, _ := time.Parse(time.RFC3339, date)
25+
return t
26+
}
27+
28+
func SetVersion(ver string) {
29+
version = ver
30+
}
31+
32+
func SetCommit(comm string) {
33+
commit = comm
34+
}
35+
36+
func SetDate(dat string) {
37+
date = dat
38+
}

0 commit comments

Comments
 (0)