diff --git a/README.md b/README.md index 5cd632b..78335c6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/internal/apirequest/dataset.go b/internal/apirequest/dataset.go index 7dec98a..7429cf6 100644 --- a/internal/apirequest/dataset.go +++ b/internal/apirequest/dataset.go @@ -9,6 +9,7 @@ import ( "strings" ) +// NewDataset creates an empty request dataset func NewDataset() *DataSet { return &DataSet{ URI: make([]*Parameter, 0), diff --git a/internal/apirequest/types.go b/internal/apirequest/types.go index 88d5922..6d6e1f8 100644 --- a/internal/apirequest/types.go +++ b/internal/apirequest/types.go @@ -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 diff --git a/internal/checker/default/varchar/main.go b/internal/checker/default/varchar/main.go index 5f8e863..05ec454 100644 --- a/internal/checker/default/varchar/main.go +++ b/internal/checker/default/varchar/main.go @@ -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 */ diff --git a/internal/clifmt/symbols.go b/internal/clifmt/symbols.go index 96865c2..d9e1619 100644 --- a/internal/clifmt/symbols.go +++ b/internal/clifmt/symbols.go @@ -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(" ") } } diff --git a/response/response.go b/response/response.go index 8e4d902..c4b101f 100644 --- a/response/response.go +++ b/response/response.go @@ -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 } diff --git a/response/types.go b/response/types.go index 0dd1ecf..93e255a 100644 --- a/response/types.go +++ b/response/types.go @@ -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