-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhttp.go
37 lines (30 loc) · 782 Bytes
/
http.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
package main
import (
"encoding/json"
"github.com/go-martini/martini"
"net/http"
)
func StartServer(password string) {
m := martini.Classic()
m.Get("/Get", LastPings)
m.Get("/Send/:ip/:token", SendPing)
m.Use(func(res http.ResponseWriter, req *http.Request) {
if req.Header.Get("X-API-KEY") != password {
res.WriteHeader(http.StatusUnauthorized)
}
})
// m.Run()
m.RunOnAddr(":2374")
}
func SendPing(rw http.ResponseWriter, req *http.Request, params martini.Params) {
for i := 0; i < 3; i++ {
SendPingPacket(params["ip"], AnycastIP, params["token"])
}
}
func LastPings(rw http.ResponseWriter, req *http.Request) {
b, err := json.Marshal(lastIPs)
if err != nil {
http.Error(rw, "Issue in making json", http.StatusInternalServerError)
}
rw.Write(b)
}