-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
37 lines (33 loc) · 797 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
package main // import "browserless"
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"browserless/cdp"
"browserless/server"
)
func main() {
defer func() {
fmt.Println("Shutting down...")
fmt.Println(cdp.ShutdownCDP(context.Background()))
}()
s := server.InitServer(":8089")
go func() {
fmt.Println(s.ListenAndServe())
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL)
sig := <-c
fmt.Println("Received", sig)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
fmt.Println(cdp.ShutdownCDP(ctx))
fmt.Println("Shutting down server...")
ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
s.Shutdown(ctx)
fmt.Println("Server out...")
}