forked from yuanjack/champloo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
37 lines (31 loc) · 675 Bytes
/
api.go
File metadata and controls
37 lines (31 loc) · 675 Bytes
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 (
"fmt"
"net/http"
"strconv"
"time"
"github.com/go-martini/martini"
)
func Heartbeat(r *http.Request, params martini.Params) string {
fmt.Println(r.URL.RequestURI())
host := r.URL.Query().Get("host")
ip := r.URL.Query().Get("ip")
port, err := strconv.Atoi(r.URL.Query().Get("port"))
if err != nil {
port = 26400
}
var server Server
db.Where(&Server{Ip: ip}).First(&server)
if server.Id <= 0 {
server = Server{
Host: host,
Ip: ip,
Port: port,
Tags: "全部",
LastHeatbeatTime: time.Now(),
}
}
server.LastHeatbeatTime = time.Now()
db.Save(&server)
return "ok"
}