aicra/internal/request/request.go

27 lines
463 B
Go
Raw Permalink Normal View History

package request
2018-06-01 08:51:51 +00:00
import (
"net/http"
"strings"
)
// 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
}