-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutdown.go
31 lines (26 loc) · 830 Bytes
/
shutdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package web
import (
"errors"
)
// shutdownError is a type used to help with the graceful termination of the service.
// [PS] Go naming convention to have error type ending with Error
type shutdownError struct {
Message string
}
// NewShutdownError returns an error that causes the framework to signal
// a graceful shutdown.
// [PS] Factory function to create and return error
func NewShutdownError(message string) error {
return &shutdownError{message}
}
// Error is the implementation of the error interface.
func (se *shutdownError) Error() string {
return se.Message
}
// IsShutdown checks to see if the shutdown error is contained
// in the specified error value.
// [PS] Helper function to check the type of the error (Assert)
func IsShutdown(err error) bool {
var se *shutdownError
return errors.As(err, &se)
}