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 */ /* (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 continue
} }
/* check parameters */ /* check parameters */
for pName, pData := range *method.Ptr.Parameters { for pName, pData := range method.Ptr.Parameters {
/* (4) Fail on invalid rename (set but empty) */ /* (4) Fail on invalid rename (set but empty) */
if pData.Rename != nil && len(*pData.Rename) < 1 { 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 */ /* (5) Check for name/rename conflict */
for paramName, param := range *method.Ptr.Parameters { for paramName, param := range method.Ptr.Parameters {
// ignore self // ignore self
if pName == paramName { if pName == paramName {

View File

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

View File

@ -19,10 +19,19 @@ func buildRequest(req *http.Request) (*Request, error) {
Uri: strings.Split(uri, "/"), Uri: strings.Split(uri, "/"),
GetData: FetchGetData(req), GetData: FetchGetData(req),
FormData: FetchFormData(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)) 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 return inst, nil
} }

View File

@ -5,6 +5,7 @@ import (
"git.xdrm.io/gfw/internal/config" "git.xdrm.io/gfw/internal/config"
"log" "log"
"net/http" "net/http"
"strings"
) )
func (s Server) route(res http.ResponseWriter, req *http.Request) { 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 /* (3) Check method
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Unavailable method */ /* (1) Unavailable method */
@ -84,6 +94,6 @@ func (s Server) route(res http.ResponseWriter, req *http.Request) {
/* (4) Check arguments /* (4) Check arguments
---------------------------------------------------------*/ ---------------------------------------------------------*/
fmt.Printf("OK\n") fmt.Printf("OK\nplugin: '%si.so'\n", strings.Join(request.ControllerUri, "/"))
return return
} }

View File

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