Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
6adaa45c
Commit
6adaa45c
authored
Mar 18, 2016
by
Adam Reese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ref(client): allow NewRequest to accept multiple types
parent
c3aaa8b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
client.go
pkg/client/client.go
+24
-1
deployments.go
pkg/client/deployments.go
+2
-4
No files found.
pkg/client/client.go
View file @
6adaa45c
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
client
import
(
"bytes"
"encoding/json"
"fmt"
"io"
...
...
@@ -103,17 +104,24 @@ func (c *Client) Get(endpoint string, v interface{}) (*Response, error) {
return
c
.
Exec
(
c
.
NewRequest
(
"GET"
,
endpoint
,
nil
),
&
v
)
}
// Post calls POST on an endpoint and decodes the response
func
(
c
*
Client
)
Post
(
endpoint
string
,
payload
,
v
interface
{})
(
*
Response
,
error
)
{
return
c
.
Exec
(
c
.
NewRequest
(
"POST"
,
endpoint
,
payload
),
&
v
)
}
// Delete calls DELETE on an endpoint and decodes the response
func
(
c
*
Client
)
Delete
(
endpoint
string
,
v
interface
{})
(
*
Response
,
error
)
{
return
c
.
Exec
(
c
.
NewRequest
(
"DELETE"
,
endpoint
,
nil
),
&
v
)
}
// NewRequest creates a new client request
func
(
c
*
Client
)
NewRequest
(
method
,
endpoint
string
,
body
io
.
Reader
)
*
Request
{
func
(
c
*
Client
)
NewRequest
(
method
,
endpoint
string
,
payload
interface
{}
)
*
Request
{
u
,
err
:=
c
.
url
(
endpoint
)
if
err
!=
nil
{
return
&
Request
{
err
:
err
}
}
body
:=
prepareBody
(
payload
)
req
,
err
:=
http
.
NewRequest
(
method
,
u
,
body
)
req
.
Header
.
Set
(
"User-Agent"
,
c
.
agent
())
...
...
@@ -122,6 +130,21 @@ func (c *Client) NewRequest(method, endpoint string, body io.Reader) *Request {
return
&
Request
{
req
,
err
}
}
func
prepareBody
(
payload
interface
{})
io
.
Reader
{
var
body
io
.
Reader
switch
t
:=
payload
.
(
type
)
{
default
:
//FIXME: panic is only for development
panic
(
fmt
.
Sprintf
(
"unexpected type %T
\n
"
,
t
))
case
io
.
Reader
:
body
=
t
case
[]
byte
:
body
=
bytes
.
NewBuffer
(
t
)
case
nil
:
}
return
body
}
// Exec sends a request and decodes the response
func
(
c
*
Client
)
Exec
(
req
*
Request
,
v
interface
{})
(
*
Response
,
error
)
{
return
c
.
Result
(
c
.
Do
(
req
),
&
v
)
...
...
pkg/client/deployments.go
View file @
6adaa45c
...
...
@@ -17,7 +17,6 @@ limitations under the License.
package
client
import
(
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
...
...
@@ -120,7 +119,6 @@ func (c *Client) PostDeployment(name string, cfg *common.Configuration) error {
}
var
out
struct
{}
b
:=
bytes
.
NewBuffer
(
data
)
return
c
.
CallService
(
"/deployments"
,
"POST"
,
&
out
,
b
)
_
,
err
=
c
.
Post
(
"/deployments"
,
data
,
&
out
)
return
err
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment