-
-
Notifications
You must be signed in to change notification settings - Fork 456
/
main.go
49 lines (39 loc) · 904 Bytes
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"github.com/cloudflare/tableflip"
"github.com/gofiber/fiber/v2"
"log"
"os"
"os/signal"
"syscall"
)
const version = "v0.0.1"
func main() {
upg, _ := tableflip.New(tableflip.Options{})
defer upg.Stop()
// By prefixing PID to log, easy to interrupt from another process.
log.SetPrefix(fmt.Sprintf("[PID: %d]", os.Getpid()))
// Listen for the process signal to trigger the tableflip upgrade.
go func() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP)
for range sig {
upg.Upgrade()
}
}()
// Listen must be called before Ready
ln, _ := upg.Listen("tcp", "localhost:8080")
defer ln.Close()
app := fiber.New()
app.Get("/version", func(c *fiber.Ctx) error {
log.Println(version)
return c.SendString(version)
})
go app.Listener(ln)
// tableflip ready
if err := upg.Ready(); err != nil {
panic(err)
}
<-upg.Exit()
}