Skip to content

Commit 268ca47

Browse files
committed
Refactor shutdown error logic
1 parent 728d1b7 commit 268ca47

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

cmd/erised/main.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ func main() {
104104

105105
go func() {
106106
if *useTLS {
107-
if err = srv.cfg.ListenAndServeTLS(*certFile, *keyFile); !errors.Is(err, http.ErrServerClosed) {
107+
if err = srv.cfg.ListenAndServeTLS(*certFile, *keyFile); err != nil && !errors.Is(err, http.ErrServerClosed) {
108108
log.Error().Msg("Server shutdown error: " + err.Error())
109109
if err = syscall.Kill(syscall.Getpid(), syscall.SIGINT); err != nil {
110110
log.Fatal().Msg(err.Error())
111111
os.Exit(1)
112112
}
113113
}
114114
} else {
115-
if err = srv.cfg.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
115+
if err = srv.cfg.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
116116
log.Error().Msg("Server shutdown error: " + err.Error())
117117
if err = syscall.Kill(syscall.Getpid(), syscall.SIGINT); err != nil {
118118
log.Fatal().Msg(err.Error())
@@ -124,12 +124,9 @@ func main() {
124124

125125
select {
126126
case <-srv.ctx.Done():
127-
if err = srv.cfg.Shutdown(srv.ctx); !errors.Is(err, context.Canceled) {
128-
if err.Error() != "" {
129-
log.Error().Msg("Context shutdown error: " + err.Error())
130-
} else {
131-
log.Error().Msg("Context shutdown error: unknown reason")
132-
}
127+
if err = srv.cfg.Shutdown(srv.ctx); err != nil && !errors.Is(err, context.Canceled) {
128+
log.Fatal().Msg("Context shutdown error: " + err.Error())
129+
os.Exit(1)
133130
}
134131
}
135132

0 commit comments

Comments
 (0)