-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_introspection.go
95 lines (70 loc) · 2.28 KB
/
api_introspection.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright © 2014-2023 Thomas Rabaix <thomas.rabaix@gmail.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package api
import (
"fmt"
"net/http"
"github.com/rande/goapp"
"github.com/rande/gonode/modules/base"
"github.com/zenazn/goji/web"
)
type Service struct {
Name string `json:"name"`
Type string `json:"type"`
}
func Api_GET_Handlers_Node(app *goapp.App) func(c web.C, res http.ResponseWriter, req *http.Request) {
collections := app.Get("gonode.handler_collection").(base.HandlerCollection)
serializer := app.Get("gonode.node.serializer").(*base.Serializer)
return func(c web.C, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "application/json")
ch := make([]*base.HandlerMetadata, 0)
for code, h := range collections {
var m *base.HandlerMetadata
if cm, ok := h.(base.MetadataHandler); ok {
m = cm.GetMetadata()
} else {
m = base.NewHandlerMetadata()
m.Name = code
}
m.Code = code
ch = append(ch, m)
}
serializer.Serialize(res, ch)
}
}
func Api_GET_Handlers_View(app *goapp.App) func(c web.C, res http.ResponseWriter, req *http.Request) {
collections := app.Get("gonode.view_handler_collection").(base.ViewHandlerCollection)
serializer := app.Get("gonode.node.serializer").(*base.Serializer)
return func(c web.C, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "application/json")
ch := make([]*base.HandlerViewMetadata, 0)
for code, h := range collections {
var m *base.HandlerViewMetadata
if cm, ok := h.(base.ViewMetadataHandler); ok {
m = cm.GetViewMetadata()
} else {
m = base.NewViewHandlerMetadata()
m.Name = code
}
m.Code = code
ch = append(ch, m)
}
serializer.Serialize(res, ch)
}
}
func Api_GET_Services(app *goapp.App) func(c web.C, res http.ResponseWriter, req *http.Request) {
serializer := app.Get("gonode.node.serializer").(*base.Serializer)
return func(c web.C, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "application/json")
ch := make([]*Service, 0)
for _, key := range app.GetKeys() {
ch = append(ch, &Service{
Name: key,
Type: fmt.Sprintf("%T", app.Get(key)),
})
}
serializer.Serialize(res, ch)
}
}