-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (40 loc) · 1023 Bytes
/
main.go
File metadata and controls
47 lines (40 loc) · 1023 Bytes
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
package main
import (
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
)
func main() {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
slog.SetDefault(logger)
// Setup the Docker client and clear any existing PR containers.
docker, err := NewDocker()
if err != nil {
panic(fmt.Errorf("new docker: %w", err))
}
defer docker.Close()
if err = docker.ClearContainers(); err != nil {
panic(fmt.Errorf("clear containers: %w", err))
}
// Create the router and start it in a goroutine.
router := NewRouter(docker, os.Getenv("API_KEY"))
go func() {
if err := router.Run(":8080"); err != nil {
panic(fmt.Errorf("run router: %w", err))
}
}()
// Gracefully handle shutdown signals.
c := make(chan os.Signal, 2)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
// Set up the listener and start listening for connections.
listener := NewListener(docker)
go func() {
<-c
listener.Close()
}()
if err := listener.Listen(":19132"); err != nil {
panic(fmt.Errorf("listen: %w", err))
}
}