-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.go
48 lines (41 loc) · 1.08 KB
/
api.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
package main
import (
"github.com/gophergala2016/dbserver/plugins"
"net/http"
"os"
)
type Api struct {
Version int
DeprecatedVersions []int
MinVersion int
Routes []*Route
Plugins map[string]Plugin
PluginsList []string
}
func (self *Api) IsDeprecated(version int) bool {
for _, deprecatedVersion := range self.DeprecatedVersions {
if version == deprecatedVersion {
return true
}
}
return false
}
func (self *Api) RegisterPlugin(name string, plugin Plugin) {
if _, err := os.Stat("plugins/" + name + ".toml"); err != nil {
return
}
plugin.ParseConfig("plugins/" + name + ".toml")
self.Plugins[name] = plugin
self.PluginsList = append(self.PluginsList, name)
}
func (self *Api) GetPlugin(name string) Plugin {
return self.Plugins[name]
}
func (self *Api) GetPlugins() []string {
return self.PluginsList
}
type Plugin interface {
ParseConfig(path string) error
Process(data map[string]interface{}, arg map[string]interface{}) *plugins.Response
ProcessBeforeHook(data map[string]interface{}, r *http.Request) *plugins.Response
}