diff --git a/internal/config/private.go b/internal/config/private.go index 4d517a4..5c58a91 100644 --- a/internal/config/private.go +++ b/internal/config/private.go @@ -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 { diff --git a/internal/config/types.go b/internal/config/types.go index 8646585..21fef94 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -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 { diff --git a/request_builder.go b/request_builder.go index fc5f163..b911541 100644 --- a/request_builder.go +++ b/request_builder.go @@ -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 } diff --git a/router.go b/router.go index 1607217..2b1b4c4 100644 --- a/router.go +++ b/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 } diff --git a/types.go b/types.go index 2256488..3758465 100644 --- a/types.go +++ b/types.go @@ -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{} }