github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/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/runtime"
    13  	"github.com/go-openapi/strfmt"
    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  /*
    45  	ChunkedOK describes a response with status code 200, with default header values.
    46  
    47  chunked data delivered
    48  */
    49  type ChunkedOK struct {
    50  	Payload io.Writer
    51  }
    52  
    53  // IsSuccess returns true when this chunked o k response returns a 2xx status code
    54  func (o *ChunkedOK) IsSuccess() bool {
    55  	return true
    56  }
    57  
    58  // IsRedirect returns true when this chunked o k response returns a 3xx status code
    59  func (o *ChunkedOK) IsRedirect() bool {
    60  	return false
    61  }
    62  
    63  // IsClientError returns true when this chunked o k response returns a 4xx status code
    64  func (o *ChunkedOK) IsClientError() bool {
    65  	return false
    66  }
    67  
    68  // IsServerError returns true when this chunked o k response returns a 5xx status code
    69  func (o *ChunkedOK) IsServerError() bool {
    70  	return false
    71  }
    72  
    73  // IsCode returns true when this chunked o k response returns a 4xx status code
    74  func (o *ChunkedOK) IsCode(code int) bool {
    75  	return code == 200
    76  }
    77  
    78  func (o *ChunkedOK) Error() string {
    79  	return fmt.Sprintf("[GET /HTTP/ChunkedScript][%d] chunkedOK  %+v", 200, o.Payload)
    80  }
    81  
    82  func (o *ChunkedOK) String() string {
    83  	return fmt.Sprintf("[GET /HTTP/ChunkedScript][%d] chunkedOK  %+v", 200, o.Payload)
    84  }
    85  
    86  func (o *ChunkedOK) GetPayload() io.Writer {
    87  	return o.Payload
    88  }
    89  
    90  func (o *ChunkedOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    91  
    92  	// response payload
    93  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
    94  		return err
    95  	}
    96  
    97  	return nil
    98  }