-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (60 loc) · 1.55 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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/velvetreactor/metrics/pkg/ynabcollector"
)
func main() {
hourlyRegistry := prometheus.NewRegistry()
ynabCollector := &ynabcollector.YNABCollector{}
hourlyRegistry.MustRegister(ynabCollector)
r := chi.NewRouter()
r.Route("/transactions", func(r chi.Router) {
})
r.Route("/notes", func(r chi.Router) {
r.Post("/", func(w http.ResponseWriter, r *http.Request) {
})
r.Get("/new", func(w http.ResponseWriter, r *http.Request) {
file, err := os.ReadFile("views/add_note.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
data := struct {
Title string
Header string
Contents template.HTML
}{
Title: "Add note",
Header: "Add note",
Contents: template.HTML(file),
}
tmpl, err := template.ParseFiles("views/layout.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
})
// Metrics
r.Get(
"/ynab/metrics",
promhttp.HandlerFor(
hourlyRegistry,
promhttp.HandlerOpts{},
).(http.HandlerFunc),
)
port := os.Getenv("METRICS_SERVER_PORT")
fmt.Printf("Server starting on port %s...\n", port)
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), r); err != nil {
log.Fatal(err)
}
}