Skip to content

Commit

Permalink
Merge pull request #21 for v0.11.3 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Aug 16, 2018
2 parents 266c519 + 94a44f6 commit 8c60eaf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<h2 align="center">HTTP extension library by aah framework</h2>
</p>
<p align="center">
<p align="center"><a href="https://travis-ci.org/go-aah/ahttp"><img src="https://travis-ci.org/go-aah/ahttp.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/ahttp/branch/master"><img src="https://codecov.io/gh/go-aah/ahttp/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/ahttp.v0"><img src="https://goreportcard.com/badge/aahframework.org/ahttp.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/ahttp/releases/latest"><img src="https://img.shields.io/badge/version-0.11.2-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/ahttp.v0"><img src="https://godoc.org/aahframework.org/ahttp.v0?status.svg" alt="Godoc"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/twitter-@aahframework-55acee.svg" alt="Twitter @aahframework"></a></p>
<p align="center"><a href="https://travis-ci.org/go-aah/ahttp"><img src="https://travis-ci.org/go-aah/ahttp.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/ahttp/branch/master"><img src="https://codecov.io/gh/go-aah/ahttp/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/ahttp.v0"><img src="https://goreportcard.com/badge/aahframework.org/ahttp.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/ahttp/releases/latest"><img src="https://img.shields.io/badge/version-0.11.3-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/ahttp.v0"><img src="https://godoc.org/aahframework.org/ahttp.v0?status.svg" alt="Godoc"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/twitter-@aahframework-55acee.svg" alt="Twitter @aahframework"></a></p>
</p>

HTTP extension Library is used to handle/process Request and Response (headers, body, gzip, etc).

### News

* `v0.11.2` [released](https://github.com/go-aah/ahttp/releases/latest) and tagged on Jul 27, 2018.
* `v0.11.3` [released](https://github.com/go-aah/ahttp/releases/latest) and tagged on Aug 15, 2018.

## Installation

Expand Down
40 changes: 40 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ type Request struct {
Header http.Header

// PathParams value is URL path parameters.
// Will be DEPRECATED in upcoming v0.12.0, URLParams will take place.
PathParams PathParams

// URLParams value is URL path parameters.
URLParams URLParams

// Referer value is HTTP 'Referrer' (or 'Referer') header.
Referer string

Expand Down Expand Up @@ -197,6 +201,9 @@ func (r *Request) URL() *url.URL {
// PathValue method returns value for given Path param key otherwise empty string.
// For eg.: /users/:userId => PathValue("userId")
func (r *Request) PathValue(key string) string {
if v := r.URLParams.Get(key); len(v) > 0 {
return v
}
return r.PathParams.Get(key)
}

Expand Down Expand Up @@ -277,6 +284,7 @@ func (r *Request) Reset() {
r.Path = ""
r.Header = nil
r.PathParams = nil
r.URLParams = nil
r.Referer = ""
r.UserAgent = ""
r.IsGzipAccepted = false
Expand All @@ -294,6 +302,38 @@ func (r *Request) cleanupMutlipart() {
}
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// URLParam
//___________________________________

// URLParam struct holds single URL parameter value.
type URLParam struct {
Key string
Value string
}

// URLParams type is slice of type URLParam.
type URLParams []URLParam

// Get method returns the value for the given key otherwise empty string.
func (u URLParams) Get(key string) string {
for i := range u {
if u[i].Key == key {
return u[i].Value
}
}
return ""
}

// ToMap method returns URL parameters in type map.
func (u URLParams) ToMap() map[string]string {
ps := make(map[string]string)
for _, p := range u {
ps[p.Key] = p.Value
}
return ps
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// PathParams
//___________________________________
Expand Down
22 changes: 22 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ func TestRequestSaveFileForExistingFile(t *testing.T) {
assert.Equal(t, int64(0), size)
}

func TestURLParams(t *testing.T) {
params := URLParams{
{
Key: "test1",
Value: "value1",
},
{
Key: "test2",
Value: "value2",
},
{
Key: "test3",
Value: "value3",
},
}

assert.Equal(t, 3, len(params))
assert.Equal(t, "value2", params.Get("test2"))
assert.Equal(t, "", params.Get("not-exists"))
assert.Equal(t, map[string]string{"test1": "value1", "test2": "value2", "test3": "value3"}, params.ToMap())
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// test unexported methods
//___________________________________
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
package ahttp

// Version no. of aah framework ahttp library
const Version = "0.11.2"
const Version = "0.11.3"

0 comments on commit 8c60eaf

Please sign in to comment.