full parameter gathering in 'request_builder'

This commit is contained in:
Adrien Marquès 2018-05-22 09:10:10 +02:00
parent 18f4bcbbae
commit 32520a1591
5 changed files with 30 additions and 9 deletions

View File

@ -34,12 +34,13 @@ func (c *Controller) format(controllerName string) error {
}
/* (3) stop if no parameter */
if method.Ptr.Parameters == nil || len(*method.Ptr.Parameters) < 1 {
if method.Ptr.Parameters == nil || len(method.Ptr.Parameters) < 1 {
method.Ptr.Parameters = make(map[string]MethodParameter, 0)
continue
}
/* check parameters */
for pName, pData := range *method.Ptr.Parameters {
for pName, pData := range method.Ptr.Parameters {
/* (4) Fail on invalid rename (set but empty) */
if pData.Rename != nil && len(*pData.Rename) < 1 {
@ -47,7 +48,7 @@ func (c *Controller) format(controllerName string) error {
}
/* (5) Check for name/rename conflict */
for paramName, param := range *method.Ptr.Parameters {
for paramName, param := range method.Ptr.Parameters {
// ignore self
if pName == paramName {

View File

@ -11,10 +11,10 @@ type MethodParameter struct {
Default *interface{} `json:"def"`
}
type Method struct {
Description string `json:"des"`
Permission [][]string `json:"per"`
Parameters *map[string]MethodParameter `json:"par"`
Options *map[string]interface{} `json:"opt"`
Description string `json:"des"`
Permission [][]string `json:"per"`
Parameters map[string]MethodParameter `json:"par"`
Options map[string]interface{} `json:"opt"`
}
type Controller struct {

View File

@ -19,10 +19,19 @@ func buildRequest(req *http.Request) (*Request, error) {
Uri: strings.Split(uri, "/"),
GetData: FetchGetData(req),
FormData: FetchFormData(req),
Data: make(map[string]interface{}),
UrlData: make(map[int]interface{}, 0),
Data: make(map[string]interface{}, 0),
}
inst.ControllerUri = make([]string, 0, len(inst.Uri))
/* (2) Fill 'Data' with all data */
for name, data := range inst.GetData {
inst.Data[fmt.Sprintf("GET_%s", name)] = data
}
for name, data := range inst.FormData {
inst.Data[name] = data
}
return inst, nil
}

View File

@ -5,6 +5,7 @@ import (
"git.xdrm.io/gfw/internal/config"
"log"
"net/http"
"strings"
)
func (s Server) route(res http.ResponseWriter, req *http.Request) {
@ -44,6 +45,15 @@ func (s Server) route(res http.ResponseWriter, req *http.Request) {
}
/* (3) Extract URI params */
uriParams := request.Uri[uriIndex:]
/* (4) Store them as Data */
for i, data := range uriParams {
request.UrlData[i] = data
request.Data[fmt.Sprintf("URL%d", i)] = data
}
/* (3) Check method
---------------------------------------------------------*/
/* (1) Unavailable method */
@ -84,6 +94,6 @@ func (s Server) route(res http.ResponseWriter, req *http.Request) {
/* (4) Check arguments
---------------------------------------------------------*/
fmt.Printf("OK\n")
fmt.Printf("OK\nplugin: '%si.so'\n", strings.Join(request.ControllerUri, "/"))
return
}

View File

@ -15,5 +15,6 @@ type Request struct {
ControllerUri []string
FormData map[string]interface{}
GetData map[string]interface{}
UrlData map[int]interface{}
Data map[string]interface{}
}