Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (86 loc) · 2.48 KB
/
Copy pathmain.go
File metadata and controls
98 lines (86 loc) · 2.48 KB
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
98
package main
import (
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gofm/db"
"io"
"log"
"net/http"
)
func isOK(w http.ResponseWriter, _ *http.Request) {
_, err := io.WriteString(w, "ok")
if err != nil {
return
}
}
var (
opsProcessedPop = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_processed_ops_pop",
})
)
var (
opsProcessedRap = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_processed_ops_rap",
})
)
var (
opsProcessedRock = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_processed_ops_rock",
})
)
var (
opsProcessedSlow = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_processed_ops_slow",
})
)
var (
opsProcessedGen = promauto.NewGauge(prometheus.GaugeOpts{
Name: "myapp_processed_ops_gen",
})
)
func main() {
log.Println("--------- LANCEMENT DE GoFM -----------")
db.Database()
myRouter := mux.NewRouter().StrictSlash(true)
internRouter := mux.NewRouter().StrictSlash(true)
hubRapRadio := newHub("rap")
go hubRapRadio.run()
go hubRapRadio.sendMusique()
hubPopRadio := newHub("pop")
go hubPopRadio.run()
go hubPopRadio.sendMusique()
hubRockRadio := newHub("rock")
go hubRockRadio.run()
go hubRockRadio.sendMusique()
hubSlowRadio := newHub("slow")
go hubSlowRadio.run()
go hubSlowRadio.sendMusique()
hubGenRadio := newHub("gen")
go hubGenRadio.run()
go hubGenRadio.sendMusique()
myRouter.HandleFunc("/rap", func(w http.ResponseWriter, r *http.Request) {
serveWs(hubRapRadio, w, r)
}).Methods(http.MethodGet)
myRouter.HandleFunc("/pop", func(w http.ResponseWriter, r *http.Request) {
serveWs(hubPopRadio, w, r)
}).Methods(http.MethodGet)
myRouter.HandleFunc("/rock", func(w http.ResponseWriter, r *http.Request) {
serveWs(hubRockRadio, w, r)
}).Methods(http.MethodGet)
myRouter.HandleFunc("/slow", func(w http.ResponseWriter, r *http.Request) {
serveWs(hubSlowRadio, w, r)
}).Methods(http.MethodGet)
myRouter.HandleFunc("/gen", func(w http.ResponseWriter, r *http.Request) {
serveWs(hubGenRadio, w, r)
}).Methods(http.MethodGet)
internRouter.Handle("/metrics", promhttp.Handler()).Methods(http.MethodGet)
internRouter.HandleFunc("/ping", isOK).Methods(http.MethodGet)
go func() {
log.Println("Server :2112 start ...")
log.Fatal(http.ListenAndServe(":2112", internRouter))
}()
log.Println("Server :8000 start ...")
log.Fatal(http.ListenAndServe(":8000", myRouter))
}