-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically reload the server after configuration changes (#22)
* Move app logic to separate structure * Moved mapping normalisation in config loading * Optimised memory allocation at starting time * Auto restert draft * Refactor server stoppting * Updated roadmap * Fixed config watching * Added graceful shutdown * Cleanup code * Move server package functionality to uncors app * Fixed linting * Added tests for restarting * WIP: tests * WIP * Removed unused deps * Enables skipped tests * Fixed tests for GracefulShutdown * Added helpers.PanicInterceptor for config reloading
- Loading branch information
Showing
32 changed files
with
891 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ __debug_bin | |
server.key | ||
server.crt | ||
dist/ | ||
uncors | ||
.idea | ||
node_modules | ||
.uncors.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
var ( | ||
notifyFn = signal.Notify | ||
sigintFix = func() { | ||
// fix prints after "^C" | ||
println("") // nolint:forbidigo | ||
} | ||
) | ||
|
||
func GracefulShutdown(ctx context.Context, shutdownFunc func(ctx context.Context) error) error { | ||
if done := waiteSignal(ctx); done { | ||
return nil | ||
} | ||
|
||
return shutdownFunc(ctx) | ||
} | ||
|
||
func waiteSignal(ctx context.Context) bool { | ||
stop := make(chan os.Signal, 1) | ||
|
||
notifyFn(stop, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) | ||
|
||
defer close(stop) | ||
|
||
select { | ||
case sig := <-stop: | ||
if sig == syscall.SIGINT { | ||
sigintFix() | ||
} | ||
case <-ctx.Done(): | ||
return true | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.