This repository was archived by the owner on May 11, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (43 loc) · 1.11 KB
/
main.go
File metadata and controls
52 lines (43 loc) · 1.11 KB
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
50
51
52
package main
import (
"context"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"time"
"github.com/google/gops/agent"
"go.octolab.org/toolkit/cli/cobra"
"github.com/kamilsk/forward/internal/cmd"
"github.com/kamilsk/forward/internal/kubernetes/cli"
"github.com/kamilsk/forward/internal/kubernetes/cli/client"
)
const unknown = "unknown"
var (
commit = unknown
date = unknown
version = "dev"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
cancel()
time.Sleep(50 * time.Millisecond) // add a possibility of shutting down subprocesses
// TODO make it better using a callback
signal.Stop(c)
fmt.Println()
os.Exit(0)
}()
go func() { _ = agent.Listen(agent.Options{ShutdownCleanup: true}) }()
go func() { _ = http.ListenAndServe(":1234", nil) }()
root := cmd.New(cli.New(client.New(ctx), os.Stderr, os.Stdout))
root.AddCommand(cobra.NewCompletionCommand(), cobra.NewVersionCommand(version, date, commit))
if err := root.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}