-
Notifications
You must be signed in to change notification settings - Fork 1
/
notice.go
55 lines (45 loc) · 862 Bytes
/
notice.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
package main
import (
"errors"
"html/template"
"log"
"os"
"time"
)
type Notice struct {
Any bool
Html template.HTML
UpdatedAt time.Time
}
func readNoticeFile(path string) (Notice, error) {
data, err := os.ReadFile(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return Notice{}, nil
} else {
return Notice{}, err
}
}
n := Notice{
Any: true,
Html: template.HTML(data),
}
info, err := os.Stat(path)
if err != nil {
log.Printf("Unable to stat notice at %v: %+v", path, err)
return n, nil
}
n.UpdatedAt = info.ModTime()
return n, nil
}
func checkNoticeFile(st *Status, path string, checkInterval time.Duration) {
for {
notice, err := readNoticeFile(path)
if err == nil && notice.Any {
st.Exporter.notice.Set(1)
} else {
st.Exporter.notice.Set(0)
}
time.Sleep(checkInterval)
}
}