/
controller_index.go
76 lines (64 loc) · 1.67 KB
/
controller_index.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
69
70
71
72
73
74
75
76
package manager
import (
"os"
"runtime"
"gopkg.in/vinxi/vinxi.v0"
"gopkg.in/vinxi/vinxi.v0/plugin"
"gopkg.in/vinxi/vinxi.v0/rule"
)
type info struct {
Hostname string `json:"hostname"`
Version string `json:"version"`
Runtime string `json:"runtime"`
Platform string `json:"platform"`
NumCPU int `json:"cpus"`
NumGoroutines int `json:"goroutines"`
Links map[string]string `json:"links"`
}
// indexController represents the base routes HTTP controller.
type indexController struct{}
func (indexController) Get(ctx *Context) {
hostname, _ := os.Hostname()
links := map[string]string{
"catalog": "/catalog",
"plugins": "/plugins",
"scopes": "/scopes",
"instances": "/instances",
"manager": "/manager",
}
ctx.SendOk(info{
Hostname: hostname,
Version: vinxi.Version,
Platform: runtime.GOOS,
Runtime: runtime.Version(),
NumCPU: runtime.NumCPU(),
NumGoroutines: runtime.NumGoroutine(),
Links: links,
})
}
func (indexController) Catalog(ctx *Context) {
rules := []rule.Info{}
for _, rule := range rule.Rules {
rules = append(rules, rule)
}
plugins := []plugin.Info{}
for _, plugin := range plugin.Plugins {
plugins = append(plugins, plugin)
}
catalog := struct {
Rules []rule.Info `json:"rules"`
Plugins []plugin.Info `json:"plugins"`
}{
Rules: rules,
Plugins: plugins,
}
ctx.SendOk(catalog)
}
func (indexController) Manager(ctx *Context) {
info := struct {
Links map[string]string `json:"links"`
}{
Links: map[string]string{"plugins": "/manager/plugins"},
}
ctx.SendOk(info)
}