-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (53 loc) · 1.32 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
package main
import (
"fmt"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
_ "net/http/pprof"
)
var pingCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "ping_request_count",
Help: "No of request handled by Ping handler",
},
)
var notificationsCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "notifications_request_count",
Help: "No of request handled by Notifications handler",
},
)
func ping(w http.ResponseWriter, req *http.Request) {
pingCounter.Inc()
fmt.Fprintf(w, "pong")
}
func main() {
prometheus.MustRegister(pingCounter)
fmt.Println("http server started")
http.HandleFunc("/ping", ping)
http.HandleFunc("/notifications", notifications)
http.HandleFunc("/mail", mail)
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8094", nil)
}
func mail(w http.ResponseWriter, req *http.Request) {
go sendMail()
fmt.Fprintf(w, "mail")
}
func notifications(w http.ResponseWriter, req *http.Request) {
notificationsCounter.Inc()
go listenAndServeNotifications()
fmt.Fprintf(w, "notifications")
}
func listenAndServeNotifications() {
for {
fmt.Println("send data to client with websocket")
time.Sleep(100 * time.Millisecond)
}
}
func sendMail() {
done := make(chan bool)
<-done
}