Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Update url encoding, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkubisa committed Sep 7, 2019
1 parent 195811b commit d330945
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/piotrkubisa/apigo
go 1.12

require (
github.com/aws/aws-lambda-go v1.11.1
github.com/aws/aws-lambda-go v1.13.1
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.4.0
)
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
github.com/aws/aws-lambda-go v1.11.1 h1:wuOnhS5aqzPOWns71FO35PtbtBKHr4MYsPVt5qXLSfI=
github.com/aws/aws-lambda-go v1.11.1/go.mod h1:Rr2SMTLeSMKgD45uep9V/NP8tnbCcySgu04cx0k/6cw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aws/aws-lambda-go v1.13.1 h1:qVIOD3UrEUo4amwgEBu6AI0CfnBsp71XJEYU05RbQ1k=
github.com/aws/aws-lambda-go v1.13.1/go.mod h1:z4ywteZ5WwbIEzG0tXizIAUlUwkTNNknX4upd5Z5XJM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
20 changes: 7 additions & 13 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ func omitBasePath(path string, basePath string) string {

// CreateRequest provides *http.Request to the RequestBuilder.
func (r *Request) CreateRequest(host string) (*http.Request, error) {
u, err := r.ParseURL(host)
if err != nil {
return nil, err
}
if err := r.ParseBody(); err != nil {
return nil, err
}

req, err := http.NewRequest(r.Event.HTTPMethod, u.String(), r.Body)
req, err := http.NewRequest(r.Event.HTTPMethod, r.ParseURL(host).String(), r.Body)
if err != nil {
return nil, err
}
Expand All @@ -78,7 +74,7 @@ func (r *Request) CreateRequest(host string) (*http.Request, error) {
}

// ParseURL provides URL (as a *url.URL) to the RequestBuilder.
func (r *Request) ParseURL(host string) (*url.URL, error) {
func (r *Request) ParseURL(host string) *url.URL {
// Whether path has been already defined (i.e. processed by previous
// function) then use it, otherwise use path from the event.
path := r.Path
Expand All @@ -87,19 +83,17 @@ func (r *Request) ParseURL(host string) (*url.URL, error) {
}

// Parse URL to *url.URL
u, err := url.Parse(path)
if err != nil {
return nil, errors.Wrap(err, "parsing path")
u := &url.URL{
Scheme: r.Event.Headers["X-Forwarded-Proto"],
Host: host,
Path: path,
}

// Query-string
q := url.Values(r.Event.MultiValueQueryStringParameters)
u.RawQuery = q.Encode()

// Host
u.Host = host

return u, nil
return u
}

// ParseBody provides body of the request to the RequestBuilder.
Expand Down

0 comments on commit d330945

Please sign in to comment.