2018-09-28 06:10:41 +00:00
|
|
|
package request
|
2018-06-01 08:51:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-07-11 17:02:33 +00:00
|
|
|
// FromHTTP builds an interface request from a http.Request
|
|
|
|
func FromHTTP(req *http.Request) (*Request, error) {
|
2018-06-01 08:51:51 +00:00
|
|
|
|
|
|
|
/* (1) Get useful data */
|
2018-07-08 23:34:21 +00:00
|
|
|
uri := normaliseURI(req.URL.Path)
|
2018-06-01 08:51:51 +00:00
|
|
|
uriparts := strings.Split(uri, "/")
|
|
|
|
|
|
|
|
/* (2) Init request */
|
|
|
|
inst := &Request{
|
2018-07-08 23:34:21 +00:00
|
|
|
URI: uriparts,
|
2018-06-01 08:51:51 +00:00
|
|
|
Path: make([]string, 0, len(uriparts)),
|
|
|
|
Data: NewDataset(),
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (3) Build dataset */
|
|
|
|
inst.Data.Build(req)
|
|
|
|
|
|
|
|
return inst, nil
|
|
|
|
}
|