2018-09-28 06:10:41 +00:00
|
|
|
package request
|
2018-06-01 08:51:51 +00:00
|
|
|
|
2018-09-13 08:21:35 +00:00
|
|
|
// Request represents a request by its URI, controller path and data (uri, get, post)
|
2018-06-01 08:51:51 +00:00
|
|
|
type Request struct {
|
|
|
|
// corresponds to the list of uri components
|
|
|
|
// featuring in the request URI
|
2018-07-08 23:34:21 +00:00
|
|
|
URI []string
|
2018-06-01 08:51:51 +00:00
|
|
|
|
|
|
|
// controller path (portion of 'Uri')
|
|
|
|
Path []string
|
|
|
|
|
|
|
|
// contains all data from URL, GET, and FORM
|
|
|
|
Data *DataSet
|
|
|
|
}
|
|
|
|
|
2018-09-13 08:21:35 +00:00
|
|
|
// DataSet represents all data that can be caught:
|
|
|
|
// - URI (guessed from the URI by removing the controller path)
|
|
|
|
// - GET (default url data)
|
|
|
|
// - POST (from json, form-data, url-encoded)
|
2018-06-01 08:51:51 +00:00
|
|
|
type DataSet struct {
|
|
|
|
|
|
|
|
// ordered values from the URI
|
|
|
|
// catches all after the controller path
|
|
|
|
//
|
2018-07-10 23:36:42 +00:00
|
|
|
// points to DataSet.Data
|
2018-07-08 23:34:21 +00:00
|
|
|
URI []*Parameter
|
2018-06-01 08:51:51 +00:00
|
|
|
|
|
|
|
// uri parameters following the QUERY format
|
|
|
|
//
|
2018-07-10 23:36:42 +00:00
|
|
|
// points to DataSet.Data
|
2018-06-01 08:51:51 +00:00
|
|
|
Get map[string]*Parameter
|
|
|
|
|
|
|
|
// form data depending on the Content-Type:
|
|
|
|
// 'application/json' => key-value pair is parsed as json into the map
|
|
|
|
// 'application/x-www-form-urlencoded' => standard parameters as QUERY parameters
|
|
|
|
// 'multipart/form-data' => parse form-data format
|
|
|
|
//
|
2018-07-10 23:36:42 +00:00
|
|
|
// points to DataSet.Data
|
2018-06-01 08:51:51 +00:00
|
|
|
Form map[string]*Parameter
|
|
|
|
|
|
|
|
// contains URL+GET+FORM data with prefixes:
|
|
|
|
// - FORM: no prefix
|
|
|
|
// - URL: 'URL#' followed by the index in Uri
|
|
|
|
// - GET: 'GET@' followed by the key in GET
|
|
|
|
Set map[string]*Parameter
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameter represents an http request parameter
|
|
|
|
// that can be of type URL, GET, or FORM (multipart, json, urlencoded)
|
|
|
|
type Parameter struct {
|
|
|
|
// whether the value has been json-parsed
|
|
|
|
// for optimisation purpose, parameters are only parsed
|
|
|
|
// if they are required by the current controller
|
|
|
|
Parsed bool
|
|
|
|
|
|
|
|
// whether the value is a file
|
|
|
|
File bool
|
|
|
|
|
|
|
|
// the actual parameter value
|
|
|
|
Value interface{}
|
|
|
|
}
|