main.go 659 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. This Source Code Form is subject to the terms of the Mozilla Public
  3. License, v. 2.0. If a copy of the MPL was not distributed with this
  4. file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. */
  6. package main
  7. import (
  8. "context"
  9. "os"
  10. "os/signal"
  11. "syscall"
  12. "idio.link/go/ipc/internal"
  13. )
  14. func main() {
  15. log := internal.NewLogger()
  16. ctx := context.WithValue(context.Background(), "log", log)
  17. ctx, cancel := context.WithCancel(ctx)
  18. log.Info("establish signal traps")
  19. go func() {
  20. c := make(chan os.Signal, 1)
  21. defer close(c)
  22. signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
  23. <-c
  24. cancel()
  25. }()
  26. log.Info("exiting: %v", err)
  27. os.Exit(1)
  28. }