From c2c1835964291bbac666ff33810579c0d7dd42a3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 1 Oct 2018 15:15:02 +0200 Subject: [PATCH] now implement plugins the right way --- controller/ROOT/main.go | 15 +++++++++++---- controller/token/main.go | 13 ++++++++++++- middleware/1-auth/main.go | 9 ++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/controller/ROOT/main.go b/controller/ROOT/main.go index 92c0975..de033ae 100644 --- a/controller/ROOT/main.go +++ b/controller/ROOT/main.go @@ -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() diff --git a/controller/token/main.go b/controller/token/main.go index 5dfdb5b..782b77b 100644 --- a/controller/token/main.go +++ b/controller/token/main.go @@ -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() } diff --git a/middleware/1-auth/main.go b/middleware/1-auth/main.go index 7a58ce5..f6c0c1a 100644 --- a/middleware/1-auth/main.go +++ b/middleware/1-auth/main.go @@ -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")