-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
97 lines (80 loc) · 1.76 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"errors"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/peterbourgon/ff/v4"
"github.com/peterbourgon/ff/v4/ffhelp"
)
const (
width = 96
)
type statusMsg map[string]int
type httpResp struct {
status int
}
type metadata struct {
title string
status string
}
func main() {
fs := ff.NewFlagSet("norav")
var (
config = fs.String('c', "config", ".norav.toml", "path to config file")
)
err := fs.Parse(os.Args[1:])
switch {
case errors.Is(err, ff.ErrHelp):
fmt.Fprintf(os.Stderr, "%s\n", ffhelp.Flags(fs))
os.Exit(0)
case err != nil:
log.Fatal(err)
}
// ====================================================================
// load config file
cfg, err := loadConfigFile(*config)
if err != nil {
log.Fatal(err)
}
// ====================================================================
// clients
httpClient := &http.Client{
Timeout: 10 * time.Second,
}
// ====================================================================
// debug logging
if len(os.Getenv("DEBUG")) > 0 {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
defer f.Close()
}
appList := list.New(
appsToItems(cfg.Applications),
list.NewDefaultDelegate(),
0,
0,
)
initialModel := model{
applications: cfg.Applications,
metadata: metadata{
title: cfg.Title,
status: "loading...",
},
client: httpClient,
healthcheckInterval: time.Duration(cfg.HealthCheckInterval) * time.Second,
applicationList: appList,
}
initialModel.applicationList.Title = cfg.Title
p := tea.NewProgram(initialModel, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}