11package main
22
33import (
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 )
0 commit comments