full parameter gathering in 'request_builder'
This commit is contained in:
parent
18f4bcbbae
commit
32520a1591
|
@ -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 {
|
||||
|
|
|
@ -13,8 +13,8 @@ type MethodParameter struct {
|
|||
type Method struct {
|
||||
Description string `json:"des"`
|
||||
Permission [][]string `json:"per"`
|
||||
Parameters *map[string]MethodParameter `json:"par"`
|
||||
Options *map[string]interface{} `json:"opt"`
|
||||
Parameters map[string]MethodParameter `json:"par"`
|
||||
Options map[string]interface{} `json:"opt"`
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
12
router.go
12
router.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue