Skip to content

Commit d525517

Browse files
committed
Cosmetic fixes
Signed-off-by: Levi Gross <[email protected]>
1 parent b0a608f commit d525517

File tree

5 files changed

+28
-37
lines changed

5 files changed

+28
-37
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2015 – Levi Gross
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# GRequests
22
A Go "clone" of the great and famous Requests library
33

4-
# Build Status
5-
![Build Status](https://circleci.com/gh/levigross/grequests.png)
4+
![[Build Status](https://circleci.com/gh/levigross/grequests.png)(https://circleci.com/gh/levigross/grequests)]
65

7-
# Docs
8-
https://godoc.org/github.com/levigross/grequests
6+
[![GoDoc](https://godoc.org/github.com/levigross/grequests?status.svg)](https://godoc.org/github.com/levigross/grequests)

base.go

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
// Package grequests implements a friendly API over Go's existing net/http library
22
package grequests // import "github.com/levigross/grequests"
33

4-
// GET takes 2 parameters and returns a Response channel. These two options are:
4+
// Get takes 2 parameters and returns a Response channel. These two options are:
55
// 1. A URL
66
// 2. A RequestOptions struct
77
// If you do not intend to use the `RequestOptions` you can just pass nil
88
func Get(url string, ro *RequestOptions) chan *Response {
9-
responseChan := make(chan *Response)
10-
go func() {
11-
responseChan <- buildResponse(buildRequest("GET", url, ro))
12-
}()
13-
return responseChan
9+
return doRequest("GET", url, ro)
1410
}
1511

1612
func Put(url string, ro *RequestOptions) chan *Response { return nil }
13+
1714
func Post(url string, ro *RequestOptions) chan *Response {
18-
responseChan := make(chan *Response)
19-
go func() {
20-
responseChan <- buildResponse(buildRequest("POST", url, ro))
21-
}()
22-
return responseChan
15+
return doRequest("POST", url, ro)
2316
}
2417
func Delete(url string, ro *RequestOptions) chan *Response { return nil }
18+
2519
func Head(url string, ro *RequestOptions) chan *Response {
26-
responseChan := make(chan *Response)
27-
go func() {
28-
responseChan <- buildResponse(buildRequest("HEAD", url, ro))
29-
}()
30-
return responseChan
20+
return doRequest("HEAD", url, ro)
3121
}
22+
3223
func Options(url string, ro *RequestOptions) chan *Response {
33-
responseChan := make(chan *Response)
34-
go func() {
35-
responseChan <- buildResponse(buildRequest("OPTIONS", url, ro))
36-
}()
37-
return responseChan
24+
return doRequest("OPTIONS", url, ro)
3825
}

base_post_test.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ type BasicPostFileUpload struct {
4848
Args struct{} `json:"args"`
4949
Data string `json:"data"`
5050
Files struct {
51-
File string `json:"file"`
52-
} `json:"files"`
51+
File string `json:"file"`
52+
} `json:"files"`
5353
Form struct{} `json:"form"`
5454
Headers struct {
55-
Accept_Encoding string `json:"Accept-Encoding"`
56-
Content_Length string `json:"Content-Length"`
57-
Content_Type string `json:"Content-Type"`
58-
Host string `json:"Host"`
59-
User_Agent string `json:"User-Agent"`
60-
} `json:"headers"`
55+
Accept_Encoding string `json:"Accept-Encoding"`
56+
Content_Length string `json:"Content-Length"`
57+
Content_Type string `json:"Content-Type"`
58+
Host string `json:"Host"`
59+
User_Agent string `json:"User-Agent"`
60+
} `json:"headers"`
6161
JSON interface{} `json:"json"`
6262
Origin string `json:"origin"`
6363
URL string `json:"url"`
6464
}
6565

66-
6766
func TestBasicPostRequest(t *testing.T) {
6867
verifyOkPostResponse(<-Post("http://httpbin.org/post",
6968
&RequestOptions{Data: map[string]string{"One": "Two"}}), t)
@@ -80,7 +79,7 @@ func TestBasicPostRequestUpload(t *testing.T) {
8079
defer fd.Close()
8180

8281
resp := <-Post("http://httpbin.org/post",
83-
&RequestOptions{File: &FileUpload{FileName: "wonderful.exe", FileContents:fd}})
82+
&RequestOptions{File: &FileUpload{FileName: "wonderful.exe", FileContents: fd}})
8483

8584
if resp.Error != nil {
8685
t.Fatal("Unable to make request", resp.Error)
@@ -92,7 +91,6 @@ func TestBasicPostRequestUpload(t *testing.T) {
9291

9392
myJsonStruct := &BasicPostFileUpload{}
9493

95-
9694
if err := resp.Json(myJsonStruct); err != nil {
9795
t.Error("Unable to coerce to JSON", err)
9896
}

request.go

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ type RequestOptions struct {
4343
Auth []string
4444
}
4545

46+
func doRequest(requestVerb, url string, ro *RequestOptions) chan *Response {
47+
responseChan := make(chan *Response)
48+
go func() {
49+
responseChan <- buildResponse(buildRequest(requestVerb, url, ro))
50+
}()
51+
return responseChan
52+
}
53+
4654
// buildRequest is where most of the magic happens for request processing
4755
func buildRequest(httpMethod, url string, ro *RequestOptions) (*http.Response, error) {
4856
if ro == nil {

0 commit comments

Comments
 (0)