2018-09-27 11:43:36 +00:00
|
|
|
package driver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.xdrm.io/go/aicra/err"
|
|
|
|
"git.xdrm.io/go/aicra/response"
|
2018-09-28 08:54:13 +00:00
|
|
|
"net/http"
|
2018-09-27 11:43:36 +00:00
|
|
|
)
|
|
|
|
|
2018-09-28 06:10:41 +00:00
|
|
|
// Driver defines the driver interface to load controller/middleware implementation or executables
|
2018-09-27 11:43:36 +00:00
|
|
|
type Driver interface {
|
2018-09-28 13:58:30 +00:00
|
|
|
Name() string
|
2018-09-28 08:54:13 +00:00
|
|
|
RunController(_path []string, _method string) (func(response.Arguments) response.Response, err.Error)
|
|
|
|
LoadMiddleware(_path string) (func(http.Request, *[]string), error)
|
2018-09-27 11:43:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 08:54:13 +00:00
|
|
|
// Generic tells the aicra instance to use the generic driver to load controller/middleware executables
|
2018-09-27 11:43:36 +00:00
|
|
|
//
|
2018-09-27 12:11:48 +00:00
|
|
|
// It will call an executable with the json input into the standard input (argument 1)
|
2018-09-27 11:43:36 +00:00
|
|
|
// the HTTP method is send as the key _HTTP_METHOD_ (in upper case)
|
|
|
|
// The standard output must be a json corresponding to the data
|
|
|
|
//
|
2018-09-28 08:54:13 +00:00
|
|
|
// CONTROLLER FILE STRUCTURE
|
2018-09-27 11:43:36 +00:00
|
|
|
// --------------
|
|
|
|
// - the root (/) controller executable must be named <WORKDIR>/controller/ROOT
|
|
|
|
// - the a/b/c controller executable must be named <WORKDIR>/controller/a/b/c
|
|
|
|
type Generic struct{}
|
|
|
|
|
2018-09-29 15:01:58 +00:00
|
|
|
// Controller is the interface that controller implementation must follow
|
|
|
|
// it is used by the 'Import' driver
|
|
|
|
type Controller interface {
|
|
|
|
Get(d response.Arguments) response.Response
|
|
|
|
Post(d response.Arguments) response.Response
|
|
|
|
Put(d response.Arguments) response.Response
|
|
|
|
Delete(d response.Arguments) response.Response
|
|
|
|
}
|
|
|
|
|
|
|
|
// Middleware is the interface that middleware implementation must follow
|
|
|
|
// it is used by the 'Import' driver
|
|
|
|
type Middleware interface {
|
|
|
|
Inspect(http.Request, *[]string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import tells the aicra instance to use the import driver to load controller/middleware executables
|
|
|
|
//
|
|
|
|
// It will compile imported with the following interface :
|
|
|
|
//
|
|
|
|
// type Controller interface {
|
|
|
|
// Get(d response.Arguments) response.Response
|
|
|
|
// Post(d response.Arguments) response.Response
|
|
|
|
// Put(d response.Arguments) response.Response
|
|
|
|
// Delete(d response.Arguments) response.Response
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// CONTROLLER FILE STRUCTURE
|
|
|
|
// --------------
|
|
|
|
// - the root (/) controller executable must be named <WORKDIR>/controller/ROOT.go
|
|
|
|
// - the a/b/c controller executable must be named <WORKDIR>/controller/a/b/c.go
|
|
|
|
//
|
|
|
|
// COMPILATION
|
|
|
|
// -----------
|
|
|
|
// The controllers/middlewares are imported and instanciated inside the main function, they are
|
|
|
|
// thus compiled with the main binary file
|
|
|
|
type Import struct {
|
|
|
|
Controllers map[string]Controller
|
|
|
|
Middlewares map[string]Middleware
|
|
|
|
}
|
|
|
|
|
2018-09-28 08:54:13 +00:00
|
|
|
// Plugin tells the aicra instance to use the plugin driver to load controller/middleware executables
|
2018-09-27 11:43:36 +00:00
|
|
|
//
|
|
|
|
// It will load go .so plugins with the following interface :
|
|
|
|
//
|
|
|
|
// type Plugin interface {
|
|
|
|
// Get(d i.Arguments, r *i.Response) i.Response
|
|
|
|
// Post(d i.Arguments, r *i.Response) i.Response
|
|
|
|
// Put(d i.Arguments, r *i.Response) i.Response
|
|
|
|
// Delete(d i.Arguments, r *i.Response) i.Response
|
|
|
|
// }
|
|
|
|
//
|
2018-09-28 08:54:13 +00:00
|
|
|
// CONTROLLER FILE STRUCTURE
|
2018-09-27 11:43:36 +00:00
|
|
|
// --------------
|
|
|
|
// - the root (/) controller executable must be named <WORKDIR>/controller/ROOT/main.so
|
|
|
|
// - the a/b/c controller executable must be named <WORKDIR>/controller/a/b/c/main.so
|
|
|
|
//
|
|
|
|
// COMPILATION
|
|
|
|
// -----------
|
|
|
|
// The compilation is handled with the command-line tool `aicra <WORKDIR>`
|
|
|
|
type Plugin struct{}
|
|
|
|
|
2018-09-28 08:54:13 +00:00
|
|
|
// FastCGI tells the aicra instance to use the fastcgi driver to load controller/middleware executables
|
2018-09-27 11:43:36 +00:00
|
|
|
//
|
|
|
|
// Warning: PHP only
|
|
|
|
//
|
|
|
|
// It will use the fastcgi protocol with php at <host>:<port>
|
|
|
|
//
|
2018-09-28 08:54:13 +00:00
|
|
|
// CONTROLLER FILE STRUCTURE
|
2018-09-27 11:43:36 +00:00
|
|
|
// --------------
|
|
|
|
// - the root (/) controller executable must be named <WORKDIR>/controller/ROOT.php
|
|
|
|
// - the a/b/c controller executable must be named <WORKDIR>/controller/a/b/c.php
|
|
|
|
type FastCGI struct {
|
|
|
|
host string
|
|
|
|
port string
|
|
|
|
}
|