update readme + comment

This commit is contained in:
Adrien Marquès 2018-09-13 10:21:35 +02:00
parent e13732c381
commit f76e3d35fa
7 changed files with 26 additions and 13 deletions

View File

@ -6,7 +6,7 @@
[![Go doc](https://godoc.org/git.xdrm.io/go/aicra?status.svg)](https://godoc.org/git.xdrm.io/go/aicra)
**Aicra** is a self-working framework coded in *Go* that allows anyone to create a fully featured REST API. It features type checking, authentication management through middlewares, file upload, rich argument parsing (*i.e. url slash-separated, urlencoded, form-data, json*), nested routes, project builder (*i.e. aicra*), etc.
**Aicra** is a self-working framework coded in *Go* that allows anyone to create a fully featured REST API. It features type checking, authentication management through middlewares, file upload, rich argument parsing (*i.e. url slash-separated, urlencoded, form-data, json*), nested routes, project compiler (*i.e. aicra*), etc.
@ -40,7 +40,7 @@ This framework is based over some of the following concepts.
#### I. Installation
You need a recent machine with `go` installed.
You need a recent machine with `go` [installed](https://golang.org/doc/install).
> This package has not been tested under the version **1.10**.
@ -66,7 +66,7 @@ go install git.xdrm.io/go/aicra/cmd/aicra
> The executable `aicra` will be placed into your `$GOPATH/bin` folder, if added to your environment PATH it should be available as a standalone command in your terminal. If not, you can simply run `$GOPATH/bin/aicra` to use the command or create a symlink into `/usr/local/bin` or the PATH folder of your choice for less characters to type.
> The executable `aicra` will be placed into your `$GOPATH/bin` folder, if added to your environment PATH it should be available as a standalone command in your terminal. If not, you can simply run `$GOPATH/bin/aicra` to use the command or create a symlink into `/usr/local/bin` for instance.
@ -105,17 +105,17 @@ The whole project behavior is described inside the `manifest.json` file. For a b
##### 2. Controllers
For each route, you'll have to place your implementation into the `controller` folder following the naming convention : add `/i.go` at the end of the route.
For each route, you'll have to place your implementation into the `controller` folder following the naming convention : add `/main.go` at the end of the route.
> Example - `/path/to/some/uri` will be inside `controller/path/to/some/uri/i.go`.
> Example - `/path/to/some/uri` will be inside `controller/path/to/some/uri/main.go`.
A fully working example is available [here](https://git.xdrm.io/example/aicra).
A sample directory structure is available [here](https://git.xdrm.io/example/aicra/src/master/controller).
##### 3. Middlewares
In order for your project to manage authentication, the best solution is to create middlewares, there are programs that updates a *Scope* according to internal or persistent (*i.e.* database) information and the actual http request. They are all run before each request it routed by aicra. The scope are used to match the `scope` field in the configuration file and automatically block non-authed requests. Scopes can also be used for implementation-specific behavior.
In order for your project to manage authentication, the best solution is to create middlewares, there are programs that updates a *Scope* according to internal or persistent (*i.e.* database) information and the actual http request. They are all run before each request is forwarded to your controller. The scope are used to match the `scope` field in the configuration file and automatically block non-authenticated requests. Scopes can also be used for implementation-specific behavior.

View File

@ -9,6 +9,7 @@ import (
"strings"
)
// NewDataset creates an empty request dataset
func NewDataset() *DataSet {
return &DataSet{
URI: make([]*Parameter, 0),

View File

@ -1,5 +1,6 @@
package apirequest
// Request represents a request by its URI, controller path and data (uri, get, post)
type Request struct {
// corresponds to the list of uri components
// featuring in the request URI
@ -12,6 +13,10 @@ type Request struct {
Data *DataSet
}
// DataSet represents all data that can be caught:
// - URI (guessed from the URI by removing the controller path)
// - GET (default url data)
// - POST (from json, form-data, url-encoded)
type DataSet struct {
// ordered values from the URI

View File

@ -8,6 +8,7 @@ import (
var min *uint64
var max *uint64
// Match filters the parameter type format "varchar(min, max)"
func Match(name string) bool {
/* (1) Create regexp */
@ -45,6 +46,7 @@ func Match(name string) bool {
}
// Check whether the given value fulfills the condition (min, max)
func Check(value interface{}) bool {
/* (1) Check if string */

View File

@ -5,8 +5,8 @@ import (
"strings"
)
var title_index = 0
var align_offset = 30
var titleIndex = 0
var alignOffset = 30
// Warn returns a red warning ASCII sign. If a string is given
// as argument, it will print it after the warning sign
@ -30,8 +30,8 @@ func Info(s ...string) string {
// Title prints a formatted title (auto-indexed from local counted)
func Title(s string) {
title_index++
fmt.Printf("\n%s |%d| %s %s\n", Color(33, ">>", false), title_index, s, Color(33, "<<", false))
titleIndex++
fmt.Printf("\n%s |%d| %s %s\n", Color(33, ">>", false), titleIndex, s, Color(33, "<<", false))
}
@ -51,7 +51,7 @@ func Align(s string) {
size += len(strings.Split(s, "\033[0m")) - 1
// 4. print trailing spaces
for i := size; i < align_offset; i++ {
for i := size; i < alignOffset; i++ {
fmt.Printf(" ")
}
}

View File

@ -4,6 +4,7 @@ import (
"git.xdrm.io/go/aicra/err"
)
// New creates an empty response
func New() *Response {
return &Response{
data: make(map[string]interface{}),
@ -11,16 +12,19 @@ func New() *Response {
}
}
// Set adds/overrides a new response field
func (i *Response) Set(name string, value interface{}) {
i.data[name] = value
}
// Get gets a reponse field
func (i *Response) Get(name string) interface{} {
value, _ := i.data[name]
return value
}
// Dump gets all key/value pairs
func (i *Response) Dump() map[string]interface{} {
return i.data
}

View File

@ -4,9 +4,10 @@ import (
"git.xdrm.io/go/aicra/err"
)
// Arguments contains all key-value arguments
type Arguments map[string]interface{}
type Controller func(Arguments, *Response) Response
// Response represents an API response to be sent
type Response struct {
data map[string]interface{}
Err err.Error