2018-05-21 10:02:24 +00:00
|
|
|
package gfw
|
|
|
|
|
|
|
|
import (
|
2018-05-24 13:54:36 +00:00
|
|
|
"git.xdrm.io/gfw/checker"
|
2018-05-21 10:02:24 +00:00
|
|
|
"git.xdrm.io/gfw/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
2018-05-24 13:54:36 +00:00
|
|
|
config *config.Controller
|
|
|
|
Params map[string]interface{}
|
|
|
|
Checker *checker.TypeRegistry // type check
|
|
|
|
err Err
|
2018-05-21 10:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Request struct {
|
2018-05-29 13:42:41 +00:00
|
|
|
// corresponds to the list of uri components
|
|
|
|
// featuring in the request URI
|
|
|
|
Uri []string
|
|
|
|
|
|
|
|
// portion of the URI that corresponds to the controllerpath
|
2018-05-21 11:02:15 +00:00
|
|
|
ControllerUri []string
|
2018-05-29 13:42:41 +00:00
|
|
|
|
|
|
|
// contains all data from URL, GET, and FORM
|
|
|
|
Data *RequestData
|
|
|
|
}
|
|
|
|
|
|
|
|
type RequestData struct {
|
|
|
|
|
|
|
|
// ordered values from the URI
|
|
|
|
// catches all after the controller path
|
|
|
|
//
|
|
|
|
// points to Request.Data
|
|
|
|
Url []*RequestParameter
|
|
|
|
|
|
|
|
// uri parameters following the QUERY format
|
|
|
|
//
|
|
|
|
// points to Request.Data
|
|
|
|
Get map[string]*RequestParameter
|
|
|
|
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// points to Request.Data
|
|
|
|
Form map[string]*RequestParameter
|
|
|
|
|
|
|
|
// 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]*RequestParameter
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestParameter represents an http request parameter
|
|
|
|
// that can be of type URL, GET, or FORM (multipart, json, urlencoded)
|
|
|
|
type RequestParameter 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{}
|
2018-05-21 10:02:24 +00:00
|
|
|
}
|