github.com/circl-dev/go-swagger@v0.31.0/examples/stream-client/client/operations/chunked_responses.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package operations
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"fmt"
    10  	"io"
    11  
    12  	"github.com/go-openapi/strfmt"
    13  	"github.com/circl-dev/runtime"
    14  )
    15  
    16  // ChunkedReader is a Reader for the Chunked structure.
    17  type ChunkedReader struct {
    18  	formats strfmt.Registry
    19  	writer  io.Writer
    20  }
    21  
    22  // ReadResponse reads a server response into the received o.
    23  func (o *ChunkedReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    24  	switch response.Code() {
    25  	case 200:
    26  		result := NewChunkedOK(o.writer)
    27  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    28  			return nil, err
    29  		}
    30  		return result, nil
    31  	default:
    32  		return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
    33  	}
    34  }
    35  
    36  // NewChunkedOK creates a ChunkedOK with default headers values
    37  func NewChunkedOK(writer io.Writer) *ChunkedOK {
    38  	return &ChunkedOK{
    39  
    40  		Payload: writer,
    41  	}
    42  }
    43  
    44  /* ChunkedOK describes a response with status code 200, with default header values.
    45  
    46  chunked data delivered
    47  */
    48  type ChunkedOK struct {
    49  	Payload io.Writer
    50  }
    51  
    52  func (o *ChunkedOK) Error() string {
    53  	return fmt.Sprintf("[GET /HTTP/ChunkedScript][%d] chunkedOK  %+v", 200, o.Payload)
    54  }
    55  func (o *ChunkedOK) GetPayload() io.Writer {
    56  	return o.Payload
    57  }
    58  
    59  func (o *ChunkedOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    60  
    61  	// response payload
    62  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
    63  		return err
    64  	}
    65  
    66  	return nil
    67  }