-
Notifications
You must be signed in to change notification settings - Fork 12
/
core_service.go
56 lines (43 loc) · 1.26 KB
/
core_service.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
package aqua
import (
"net/http"
"runtime"
"time"
"github.com/pivotal-golang/bytefmt"
// "code.cloudfoundry.org/bytefmt"
)
type CoreService struct {
RestService `root:"/aqua/"`
ping GetApi `url:"/ping"`
status GetApi `url:"/status" pretty:"true"`
date GetApi `url:"/time"`
}
func (me *CoreService) Ping() string {
return "pong"
}
func (me *CoreService) Status() *Sac {
out := NewSac()
m := runtime.MemStats{}
runtime.ReadMemStats(&m)
mem := NewSac()
mem_gen := NewSac().
Set("alloc", bytefmt.ByteSize(m.Alloc)).
Set("total_alloc", bytefmt.ByteSize(m.TotalAlloc))
mem.Set("general", mem_gen)
mem_hp := NewSac().
Set("alloc", bytefmt.ByteSize(m.HeapAlloc)).
Set("sys", bytefmt.ByteSize(m.HeapAlloc)).
Set("idle", bytefmt.ByteSize(m.HeapIdle)).
Set("inuse", bytefmt.ByteSize(m.HeapInuse)).
Set("released", bytefmt.ByteSize(m.HeapReleased)).
Set("objects", bytefmt.ByteSize(m.HeapObjects))
mem.Set("heap", mem_hp)
out.Set("mem", mem).
Set("server-time", time.Now().Format("2006-01-02 15:04:05 MST")).
Set("go-version", runtime.Version()[2:]).
Set("aqua-version", release)
return out
}
func (me *CoreService) Date(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(time.Now().Format("2006-01-02 15:04:05 MST")))
}