Skip to content

Commit 0e30eed

Browse files
committed
fix(backend): make lint happy
Signed-off-by: Me0wo <152751263+Sn0wo2@users.noreply.github.com>
1 parent 4b5f116 commit 0e30eed

1 file changed

Lines changed: 73 additions & 74 deletions

File tree

main.go

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,86 @@
11
package main
22

33
import (
4-
"os"
5-
"os/signal"
6-
"runtime"
7-
"runtime/debug"
8-
"syscall"
9-
10-
"github.com/Sn0wo2/QuickNote/internal/listener"
11-
"github.com/Sn0wo2/QuickNote/internal/router"
12-
"github.com/Sn0wo2/QuickNote/internal/setup"
13-
"github.com/Sn0wo2/QuickNote/pkg/config"
14-
"github.com/Sn0wo2/QuickNote/pkg/database/orm"
15-
"github.com/Sn0wo2/QuickNote/pkg/database/table"
16-
"github.com/Sn0wo2/QuickNote/pkg/log"
17-
"github.com/Sn0wo2/QuickNote/pkg/version"
18-
"github.com/gofiber/fiber/v2"
19-
"github.com/joho/godotenv"
20-
"go.uber.org/zap"
4+
"os"
5+
"os/signal"
6+
"runtime/debug"
7+
"syscall"
8+
9+
"github.com/Sn0wo2/QuickNote/internal/listener"
10+
"github.com/Sn0wo2/QuickNote/internal/router"
11+
"github.com/Sn0wo2/QuickNote/internal/setup"
12+
"github.com/Sn0wo2/QuickNote/pkg/config"
13+
"github.com/Sn0wo2/QuickNote/pkg/database/orm"
14+
"github.com/Sn0wo2/QuickNote/pkg/database/table"
15+
"github.com/Sn0wo2/QuickNote/pkg/log"
16+
"github.com/Sn0wo2/QuickNote/pkg/version"
17+
"github.com/gofiber/fiber/v2"
18+
"github.com/joho/godotenv"
19+
"go.uber.org/zap"
2120
)
2221

2322
func init() {
24-
// stw
25-
debug.SetGCPercent(50)
23+
// stw
24+
debug.SetGCPercent(50)
2625

27-
_ = godotenv.Load()
26+
_ = godotenv.Load()
2827

29-
err := config.Init()
30-
if err != nil {
31-
// log not init~
32-
panic(err)
33-
}
28+
err := config.Init()
29+
if err != nil {
30+
// log not init~
31+
panic(err)
32+
}
3433

35-
log.Init()
34+
log.Init()
3635
}
3736

3837
func main() {
39-
defer func() {
40-
_ = log.Instance.Sync()
41-
}()
42-
43-
if !fiber.IsChild() {
44-
log.Instance.Info("Starting QuickNote...", zap.String("version", version.GetFormatVersion()))
45-
}
46-
47-
if err := orm.Init(config.Instance.Database.Type, config.Instance.Database.URL); err != nil {
48-
log.Instance.Fatal("Failed to initialize database",
49-
zap.Error(err),
50-
)
51-
}
52-
53-
if err := table.Init(); err != nil {
54-
log.Instance.Fatal("Failed to initialize tables",
55-
zap.Error(err),
56-
)
57-
}
58-
59-
if !fiber.IsChild() {
60-
log.Instance.Info("Starting server",
61-
zap.String("address", config.Instance.Listener.Address),
62-
zap.Int("pid", os.Getpid()),
63-
)
64-
}
65-
66-
app := setup.Fiber()
67-
router.Setup(app)
68-
69-
shutdownChan := make(chan os.Signal, 1)
70-
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
71-
72-
go func() {
73-
if err := listener.Start(app); err != nil {
74-
log.Instance.Fatal("Server failed to start",
75-
zap.Error(err),
76-
)
77-
}
78-
}()
79-
80-
<-shutdownChan
81-
82-
if err := app.Shutdown(); err != nil {
83-
log.Instance.Error("Server shutdown error",
84-
zap.Error(err),
85-
)
86-
}
38+
defer func() {
39+
_ = log.Instance.Sync()
40+
}()
41+
42+
if !fiber.IsChild() {
43+
log.Instance.Info("Starting QuickNote...", zap.String("version", version.GetFormatVersion()))
44+
}
45+
46+
if err := orm.Init(config.Instance.Database.Type, config.Instance.Database.URL); err != nil {
47+
log.Instance.Fatal("Failed to initialize database",
48+
zap.Error(err),
49+
)
50+
}
51+
52+
if err := table.Init(); err != nil {
53+
log.Instance.Fatal("Failed to initialize tables",
54+
zap.Error(err),
55+
)
56+
}
57+
58+
if !fiber.IsChild() {
59+
log.Instance.Info("Starting server",
60+
zap.String("address", config.Instance.Listener.Address),
61+
zap.Int("pid", os.Getpid()),
62+
)
63+
}
64+
65+
app := setup.Fiber()
66+
router.Setup(app)
67+
68+
shutdownChan := make(chan os.Signal, 1)
69+
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
70+
71+
go func() {
72+
if err := listener.Start(app); err != nil {
73+
log.Instance.Fatal("Server failed to start",
74+
zap.Error(err),
75+
)
76+
}
77+
}()
78+
79+
<-shutdownChan
80+
81+
if err := app.Shutdown(); err != nil {
82+
log.Instance.Error("Server shutdown error",
83+
zap.Error(err),
84+
)
85+
}
8786
}

0 commit comments

Comments
 (0)