now implement plugins the right way

This commit is contained in:
Adrien Marquès 2018-10-01 15:15:02 +02:00
parent 6c364e9317
commit c2c1835964
3 changed files with 31 additions and 6 deletions

View File

@ -2,13 +2,20 @@ package main
import (
"git.xdrm.io/example/aicra/db"
"git.xdrm.io/go/aicra/driver"
e "git.xdrm.io/go/aicra/err"
"git.xdrm.io/go/aicra/response"
i "git.xdrm.io/go/aicra/response"
)
func main() {}
type RootController int
func Export() driver.Controller { return new(RootController) }
// Redirects to an url from a key
func Get(d i.Arguments) i.Response {
func (rctl RootController) Get(d i.Arguments) i.Response {
r := response.New()
@ -42,7 +49,7 @@ func Get(d i.Arguments) i.Response {
}
// Stores a new tinyurl/fullurl combination
func Post(d i.Arguments) i.Response {
func (rctl RootController) Post(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */
@ -78,7 +85,7 @@ func Post(d i.Arguments) i.Response {
}
// Overrides a existing tinyurl with new target
func Put(d i.Arguments) i.Response {
func (rctl RootController) Put(d i.Arguments) i.Response {
r := response.New()
@ -115,7 +122,7 @@ func Put(d i.Arguments) i.Response {
}
// Deletes an existing tinyurl
func Delete(d i.Arguments) i.Response {
func (rctl RootController) Delete(d i.Arguments) i.Response {
r := response.New()

View File

@ -4,6 +4,7 @@ import (
"crypto/sha512"
"encoding/hex"
"git.xdrm.io/example/aicra/db"
"git.xdrm.io/go/aicra/driver"
e "git.xdrm.io/go/aicra/err"
"git.xdrm.io/go/aicra/response"
i "git.xdrm.io/go/aicra/response"
@ -11,8 +12,14 @@ import (
"time"
)
func main() {}
type TokenController int
func Export() driver.Controller { return new(TokenController) }
// Builds an access token from credentials
func Post(d i.Arguments) i.Response {
func (tctl TokenController) Post(d i.Arguments) i.Response {
r := response.New()
@ -47,3 +54,7 @@ func Post(d i.Arguments) i.Response {
r.Err = e.Success
return *r
}
func (tctl TokenController) Get(d i.Arguments) i.Response { return *i.New() }
func (tctl TokenController) Put(d i.Arguments) i.Response { return *i.New() }
func (tctl TokenController) Delete(d i.Arguments) i.Response { return *i.New() }

View File

@ -2,12 +2,19 @@ package main
import (
"git.xdrm.io/example/aicra/db"
"git.xdrm.io/go/aicra/driver"
"net/http"
"strings"
)
func main() {}
type AuthMiddleware int
func Export() driver.Middleware { return new(AuthMiddleware) }
// Authentication middleware
func Inspect(req http.Request, scope *[]string) {
func (amw AuthMiddleware) Inspect(req http.Request, scope *[]string) {
// 1. get authorization header
token := req.Header.Get("Authorization")