Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bee68e48
Commit
bee68e48
authored
Jun 18, 2015
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have client store status code in Result
parent
64bee7f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
request.go
pkg/client/request.go
+14
-7
request_test.go
pkg/client/request_test.go
+1
-1
No files found.
pkg/client/request.go
View file @
bee68e48
...
@@ -803,9 +803,9 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
...
@@ -803,9 +803,9 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
}
}
return
Result
{
return
Result
{
body
:
body
,
body
:
body
,
created
:
resp
.
StatusCode
==
http
.
StatusCreated
,
statusCode
:
resp
.
StatusCode
,
codec
:
r
.
codec
,
codec
:
r
.
codec
,
}
}
}
}
...
@@ -879,9 +879,9 @@ func retryAfterSeconds(resp *http.Response) (int, bool) {
...
@@ -879,9 +879,9 @@ func retryAfterSeconds(resp *http.Response) (int, bool) {
// Result contains the result of calling Request.Do().
// Result contains the result of calling Request.Do().
type
Result
struct
{
type
Result
struct
{
body
[]
byte
body
[]
byte
created
bool
err
error
err
error
statusCode
int
codec
runtime
.
Codec
codec
runtime
.
Codec
}
}
...
@@ -899,6 +899,13 @@ func (r Result) Get() (runtime.Object, error) {
...
@@ -899,6 +899,13 @@ func (r Result) Get() (runtime.Object, error) {
return
r
.
codec
.
Decode
(
r
.
body
)
return
r
.
codec
.
Decode
(
r
.
body
)
}
}
// StatusCode returns the HTTP status code of the request. (Only valid if no
// error was returned.)
func
(
r
Result
)
StatusCode
(
statusCode
*
int
)
Result
{
*
statusCode
=
r
.
statusCode
return
r
}
// Into stores the result into obj, if possible.
// Into stores the result into obj, if possible.
func
(
r
Result
)
Into
(
obj
runtime
.
Object
)
error
{
func
(
r
Result
)
Into
(
obj
runtime
.
Object
)
error
{
if
r
.
err
!=
nil
{
if
r
.
err
!=
nil
{
...
@@ -910,7 +917,7 @@ func (r Result) Into(obj runtime.Object) error {
...
@@ -910,7 +917,7 @@ func (r Result) Into(obj runtime.Object) error {
// WasCreated updates the provided bool pointer to whether the server returned
// WasCreated updates the provided bool pointer to whether the server returned
// 201 created or a different response.
// 201 created or a different response.
func
(
r
Result
)
WasCreated
(
wasCreated
*
bool
)
Result
{
func
(
r
Result
)
WasCreated
(
wasCreated
*
bool
)
Result
{
*
wasCreated
=
r
.
c
reated
*
wasCreated
=
r
.
statusCode
==
http
.
StatusC
reated
return
r
return
r
}
}
...
...
pkg/client/request_test.go
View file @
bee68e48
...
@@ -274,7 +274,7 @@ func TestTransformResponse(t *testing.T) {
...
@@ -274,7 +274,7 @@ func TestTransformResponse(t *testing.T) {
test
.
Response
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
{}))
test
.
Response
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
{}))
}
}
result
:=
r
.
transformResponse
(
test
.
Response
,
&
http
.
Request
{})
result
:=
r
.
transformResponse
(
test
.
Response
,
&
http
.
Request
{})
response
,
created
,
err
:=
result
.
body
,
result
.
c
reated
,
result
.
err
response
,
created
,
err
:=
result
.
body
,
result
.
statusCode
==
http
.
StatusC
reated
,
result
.
err
hasErr
:=
err
!=
nil
hasErr
:=
err
!=
nil
if
hasErr
!=
test
.
Error
{
if
hasErr
!=
test
.
Error
{
t
.
Errorf
(
"%d: unexpected error: %t %v"
,
i
,
test
.
Error
,
err
)
t
.
Errorf
(
"%d: unexpected error: %t %v"
,
i
,
test
.
Error
,
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