Skip to content

Commit

Permalink
chore: v1.0.4 (#7)
Browse files Browse the repository at this point in the history
* chore: v1.0.4

* chore: fix
  • Loading branch information
henomis authored Aug 6, 2023
1 parent 1662468 commit 66aae74
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/cmd/context/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (r *TodoResponse) SetStatusCode(code int) error {
return nil
}

func (r *TodoResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/delete/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (r *DeletePostResponse) SetStatusCode(code int) error {
return nil
}

func (r *DeletePostResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (r *TodoResponse) SetStatusCode(code int) error {
return nil
}

func (r *TodoResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/patch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (r *UpdatePostResponse) SetStatusCode(code int) error {
return nil
}

func (r *UpdatePostResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/post/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (r *CreatePostResponse) SetStatusCode(code int) error {
return nil
}

func (r *CreatePostResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/put/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (r *UpdatePostResponse) SetStatusCode(code int) error {
return nil
}

func (r *UpdatePostResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
2 changes: 2 additions & 0 deletions examples/cmd/url_values/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (r *CommentsResponse) SetStatusCode(code int) error {
return nil
}

func (r *CommentsResponse) SetHeaders(headers map[string]string) error { return nil }

func main() {

restClient := restclientgo.New("https://jsonplaceholder.typicode.com")
Expand Down
12 changes: 12 additions & 0 deletions restclientgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Response interface {
AcceptContentType() string
// SetStatusCode sets the HTTP response status code.
SetStatusCode(code int) error
// SetHeaders sets the HTTP response headers.
SetHeaders(headers map[string]string) error
}

// New creates a new RestClient.
Expand Down Expand Up @@ -148,6 +150,16 @@ func (r *RestClient) do(ctx context.Context, method httpMethod, request Request,
return nil
}

headers := make(map[string]string)
for k, v := range httpResponse.Header {
headers[k] = strings.Join(v, ",")
}

err = response.SetHeaders(headers)
if err != nil {
return err
}

if response.AcceptContentType() == "" {
response.SetBody(httpResponse.Body)
return nil
Expand Down
4 changes: 4 additions & 0 deletions restclientgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (r *TodoResponse) SetStatusCode(code int) error {
r.HTTPStatusCode = code
return nil
}
func (r *TodoResponse) SetHeaders(headers map[string]string) error { return nil }

//---------------------------------------------

Expand Down Expand Up @@ -64,6 +65,7 @@ func (r *DeletePostResponse) SetStatusCode(code int) error {
r.HTTPStatusCode = code
return nil
}
func (r *DeletePostResponse) SetHeaders(headers map[string]string) error { return nil }

// ---------------------------------------------

Expand Down Expand Up @@ -104,6 +106,7 @@ func (r *UpdatePostResponse) SetStatusCode(code int) error {
r.HTTPStatusCode = code
return nil
}
func (r *UpdatePostResponse) SetHeaders(headers map[string]string) error { return nil }

// ---------------------------------------------

Expand Down Expand Up @@ -145,6 +148,7 @@ func (r *CreatePostResponse) SetStatusCode(code int) error {
r.HTTPStatusCode = code
return nil
}
func (r *CreatePostResponse) SetHeaders(headers map[string]string) error { return nil }

// ---------------------------------------------

Expand Down

0 comments on commit 66aae74

Please sign in to comment.