[mirror] Scalable static site server for Git forges (like GitHub Pages)
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify signal handling code.

This does not require `//go:build`.

+29 -40
+29
src/signal.go
··· 1 + // See https://pkg.go.dev/os/signal#hdr-Windows for a description of what this module 2 + // will do on Windows (tl;dr nothing calls the reload handler, the interrupt handler works 3 + // more or less how you'd expect). 4 + 5 + package git_pages 6 + 7 + import ( 8 + "os" 9 + "os/signal" 10 + "syscall" 11 + ) 12 + 13 + func OnReload(handler func()) { 14 + sighup := make(chan os.Signal, 1) 15 + signal.Notify(sighup, syscall.SIGHUP) 16 + go func() { 17 + for { 18 + <-sighup 19 + handler() 20 + } 21 + }() 22 + } 23 + 24 + func WaitForInterrupt() { 25 + sigint := make(chan os.Signal, 1) 26 + signal.Notify(sigint, syscall.SIGINT, syscall.SIGTERM) 27 + <-sigint 28 + signal.Stop(sigint) 29 + }
-13
src/signal_other.go
··· 1 - //go:build !unix 2 - 3 - package git_pages 4 - 5 - func OnReload(handler func()) { 6 - // not implemented 7 - } 8 - 9 - func WaitForInterrupt() { 10 - for { 11 - // Ctrl+C not supported 12 - } 13 - }
-27
src/signal_posix.go
··· 1 - //go:build unix 2 - 3 - package git_pages 4 - 5 - import ( 6 - "os" 7 - "os/signal" 8 - "syscall" 9 - ) 10 - 11 - func OnReload(handler func()) { 12 - sighup := make(chan os.Signal, 1) 13 - signal.Notify(sighup, syscall.SIGHUP) 14 - go func() { 15 - for { 16 - <-sighup 17 - handler() 18 - } 19 - }() 20 - } 21 - 22 - func WaitForInterrupt() { 23 - sigint := make(chan os.Signal, 1) 24 - signal.Notify(sigint, syscall.SIGINT) 25 - <-sigint 26 - signal.Stop(sigint) 27 - }