update according to go/aicra release 0.1.1

This commit is contained in:
Adrien Marquès 2018-09-28 16:06:20 +02:00
parent e66afdab80
commit d30dee5013
4 changed files with 21 additions and 9 deletions

View File

@ -3,11 +3,14 @@ package main
import ( import (
"git.xdrm.io/example/aicra/db" "git.xdrm.io/example/aicra/db"
e "git.xdrm.io/go/aicra/err" e "git.xdrm.io/go/aicra/err"
"git.xdrm.io/go/aicra/response"
i "git.xdrm.io/go/aicra/response" i "git.xdrm.io/go/aicra/response"
) )
// Redirects to an url from a key // Redirects to an url from a key
func Get(d i.Arguments, r *i.Response) i.Response { func Get(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */ /* (1) Init redis connection */
cli := db.Connect() cli := db.Connect()
@ -39,7 +42,9 @@ func Get(d i.Arguments, r *i.Response) i.Response {
} }
// Stores a new tinyurl/fullurl combination // Stores a new tinyurl/fullurl combination
func Post(d i.Arguments, r *i.Response) i.Response { func Post(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */ /* (1) Init redis connection */
cli := db.Connect() cli := db.Connect()
if cli == nil { if cli == nil {
@ -73,7 +78,9 @@ func Post(d i.Arguments, r *i.Response) i.Response {
} }
// Overrides a existing tinyurl with new target // Overrides a existing tinyurl with new target
func Put(d i.Arguments, r *i.Response) i.Response { func Put(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */ /* (1) Init redis connection */
cli := db.Connect() cli := db.Connect()
@ -108,7 +115,9 @@ func Put(d i.Arguments, r *i.Response) i.Response {
} }
// Deletes an existing tinyurl // Deletes an existing tinyurl
func Delete(d i.Arguments, r *i.Response) i.Response { func Delete(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */ /* (1) Init redis connection */
cli := db.Connect() cli := db.Connect()

View File

@ -5,13 +5,16 @@ import (
"encoding/hex" "encoding/hex"
"git.xdrm.io/example/aicra/db" "git.xdrm.io/example/aicra/db"
e "git.xdrm.io/go/aicra/err" e "git.xdrm.io/go/aicra/err"
"git.xdrm.io/go/aicra/response"
i "git.xdrm.io/go/aicra/response" i "git.xdrm.io/go/aicra/response"
"strconv" "strconv"
"time" "time"
) )
// Builds an access token from credentials // Builds an access token from credentials
func Post(d i.Arguments, r *i.Response) i.Response { func Post(d i.Arguments) i.Response {
r := response.New()
/* (1) Init redis connection */ /* (1) Init redis connection */
cli := db.Connect() cli := db.Connect()

View File

@ -2,6 +2,7 @@ package main
import ( import (
"git.xdrm.io/go/aicra" "git.xdrm.io/go/aicra"
"git.xdrm.io/go/aicra/driver"
"log" "log"
"net/http" "net/http"
) )
@ -10,9 +11,9 @@ func main() {
listen_addr := "127.0.0.1:4242" listen_addr := "127.0.0.1:4242"
server, err := aicra.New("manifest.json") server, err := aicra.New("manifest.json", new(driver.Plugin))
if err != nil { if err != nil {
panic("cannot load config") panic(err)
} }
log.Printf("[Server up] %s\n", listen_addr) log.Printf("[Server up] %s\n", listen_addr)

View File

@ -2,13 +2,12 @@ package main
import ( import (
"git.xdrm.io/example/aicra/db" "git.xdrm.io/example/aicra/db"
"git.xdrm.io/go/aicra/middleware"
"net/http" "net/http"
"strings" "strings"
) )
// Authentication middleware // Authentication middleware
func Inspect(req http.Request, scope *middleware.Scope) { func Inspect(req http.Request, scope *[]string) {
// 1. get authorization header // 1. get authorization header
token := req.Header.Get("Authorization") token := req.Header.Get("Authorization")