Skip to content

Commit e2d5581

Browse files
lvan100lianghuan
authored andcommitted
refactor(gs_app): add log destroy
1 parent ab02a57 commit e2d5581

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/expr-lang/expr v1.17.5
77
github.com/go-spring/gs-assert v1.0.2
88
github.com/go-spring/gs-mock v0.0.4
9-
github.com/go-spring/log v0.0.4
9+
github.com/go-spring/log v0.0.5
1010
github.com/magiconair/properties v1.8.10
1111
github.com/pelletier/go-toml v1.9.5
1212
github.com/spf13/cast v1.9.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/go-spring/gs-assert v1.0.2 h1:9vDppl7ZwMvQE4c83ac7GzN0VxZC5BrQue7dND7
66
github.com/go-spring/gs-assert v1.0.2/go.mod h1:FfibkqWz4HUBpbig1cKMlzW8Ha7RywTB93f1Q/NuF9I=
77
github.com/go-spring/gs-mock v0.0.4 h1:f34YN+ntXflfn13aLa3ZVCB78IG7wWZGK4y5tB+OGpI=
88
github.com/go-spring/gs-mock v0.0.4/go.mod h1:QK0PqZ+Vu9F+BU97zl8fip5XKibvDSoN+ofky413Z6Q=
9-
github.com/go-spring/log v0.0.4 h1:gmYPCBt9jH8k5FsbS7WvICiK1aN9mEqXwz2XNvGxKfQ=
10-
github.com/go-spring/log v0.0.4/go.mod h1:9SWgPEVWSGgloRTGR7niBliqfwC5UCjPUOl2jyJOimM=
9+
github.com/go-spring/log v0.0.5 h1:a8yiGmZTS7MPYvYvePXtc0hIdaQ76pLdsXt8iJwgQBQ=
10+
github.com/go-spring/log v0.0.5/go.mod h1:9SWgPEVWSGgloRTGR7niBliqfwC5UCjPUOl2jyJOimM=
1111
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
1212
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1313
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

gs/app.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ import (
2525

2626
type AppStarter struct{}
2727

28-
// Run runs the app and waits for an interrupt signal to exit.
29-
func (s *AppStarter) Run() {
30-
s.RunWith(nil)
31-
}
32-
3328
// initApp initializes the app.
3429
func (s *AppStarter) initApp() error {
3530
printBanner()
@@ -43,6 +38,11 @@ func (s *AppStarter) initApp() error {
4338
return nil
4439
}
4540

41+
// Run runs the app and waits for an interrupt signal to exit.
42+
func (s *AppStarter) Run() {
43+
s.RunWith(nil)
44+
}
45+
4646
// RunWith runs the app with a given function and waits for an interrupt signal to exit.
4747
func (s *AppStarter) RunWith(fn func(ctx context.Context) error) {
4848
var err error
@@ -54,7 +54,10 @@ func (s *AppStarter) RunWith(fn func(ctx context.Context) error) {
5454
if err = s.initApp(); err != nil {
5555
return
5656
}
57-
err = gs_app.GS.RunWith(fn)
57+
if err = gs_app.GS.RunWith(fn); err != nil {
58+
return
59+
}
60+
log.Destroy()
5861
}
5962

6063
// RunAsync runs the app asynchronously and returns a function to stop the app.
@@ -65,5 +68,8 @@ func (s *AppStarter) RunAsync() (func(), error) {
6568
if err := gs_app.GS.Start(); err != nil {
6669
return nil, err
6770
}
68-
return func() { gs_app.GS.Stop() }, nil
71+
return func() {
72+
gs_app.GS.Stop()
73+
log.Destroy()
74+
}, nil
6975
}

0 commit comments

Comments
 (0)