Skip to content

Commit 27a6e7f

Browse files
committed
Added jwt plugin to api
1 parent 075039f commit 27a6e7f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

api.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package main
22

3+
import (
4+
"github.com/gophergala2016/dbserver/plugins"
5+
"os"
6+
)
7+
38
type Api struct {
49
Version int
510
DeprecatedVersions []int
611
MinVersion int
712
Routes []*Route
13+
Plugins map[string]Plugin
814
}
915

1016
func (self *Api) IsDeprecated(version int) bool {
@@ -15,3 +21,20 @@ func (self *Api) IsDeprecated(version int) bool {
1521
}
1622
return false
1723
}
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+
}

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
"encoding/json"
66
"fmt"
7+
"github.com/gophergala2016/dbserver/plugins/jwt"
78
"github.com/julienschmidt/httprouter"
89
"log"
910
"net/http"
@@ -120,6 +121,9 @@ func main() {
120121
if err != nil {
121122
log.Fatal(err)
122123
}
124+
//Plugins
125+
api.RegisterPlugin("jwt", &jwt.JWT{})
126+
//Plugins
123127
db, err = GetDbConnection()
124128
if err != nil {
125129
log.Fatal(err)

0 commit comments

Comments
 (0)