File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
+ import (
4
+ "github.com/gophergala2016/dbserver/plugins"
5
+ "os"
6
+ )
7
+
3
8
type Api struct {
4
9
Version int
5
10
DeprecatedVersions []int
6
11
MinVersion int
7
12
Routes []* Route
13
+ Plugins map [string ]Plugin
8
14
}
9
15
10
16
func (self * Api ) IsDeprecated (version int ) bool {
@@ -15,3 +21,20 @@ func (self *Api) IsDeprecated(version int) bool {
15
21
}
16
22
return false
17
23
}
24
+
25
+ func (self * Api ) RegisterPlugin (name string , plugin Plugin ) {
26
+ if _ , err := os .Stat ("plugins/" + name + ".toml" ); err != nil {
27
+ return
28
+ }
29
+ plugin .ParseConfig ("plugins/" + name + ".toml" )
30
+ self .Plugins [name ] = plugin
31
+ }
32
+
33
+ func (self * Api ) GetPlugin (name string ) Plugin {
34
+ return self .Plugins [name ]
35
+ }
36
+
37
+ type Plugin interface {
38
+ ParseConfig (path string ) error
39
+ Process (data map [string ]interface {}, arg map [string ]interface {}) * plugins.Response
40
+ }
Original file line number Diff line number Diff line change 4
4
"database/sql"
5
5
"encoding/json"
6
6
"fmt"
7
+ "github.com/gophergala2016/dbserver/plugins/jwt"
7
8
"github.com/julienschmidt/httprouter"
8
9
"log"
9
10
"net/http"
@@ -120,6 +121,9 @@ func main() {
120
121
if err != nil {
121
122
log .Fatal (err )
122
123
}
124
+ //Plugins
125
+ api .RegisterPlugin ("jwt" , & jwt.JWT {})
126
+ //Plugins
123
127
db , err = GetDbConnection ()
124
128
if err != nil {
125
129
log .Fatal (err )
You can’t perform that action at this time.
0 commit comments