-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (73 loc) · 1.6 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
package main
import (
"flag"
"log"
"net/http"
"os"
"path/filepath"
"time"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func metrics() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":7878", nil))
}
func main() {
var dir, dir2 string
flag.StringVar(&dir, "dir", "/data/pear", "dir")
flag.StringVar(&dir2, "dir2", "/data/pear_pvc", "dir2")
flag.Parse()
go metrics()
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
err := os.MkdirAll(dir, 0777)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
f, err := os.OpenFile(filepath.Join(dir, "data.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
defer f.Close()
_, err = f.WriteString(time.Now().Format("Mon Jan 2 15:04:05 -0700 MST 2006") + "\n")
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
err = os.MkdirAll(dir2, 0777)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
f2, err := os.OpenFile(filepath.Join(dir2, "data.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
defer f2.Close()
_, err = f2.WriteString(time.Now().Format("Mon Jan 2 15:04:05 -0700 MST 2006") + "\n")
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
c.JSON(200, gin.H{
"message": "today is yesterday",
})
})
r.Run(":6666") // listen and serve on 0.0.0.0:8080
}