github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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("[GET /HTTP/ChunkedScript] chunked", 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 has 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 has 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 has 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 has 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 a status code equal to that given 74 func (o *ChunkedOK) IsCode(code int) bool { 75 return code == 200 76 } 77 78 // Code gets the status code for the chunked o k response 79 func (o *ChunkedOK) Code() int { 80 return 200 81 } 82 83 func (o *ChunkedOK) Error() string { 84 return fmt.Sprintf("[GET /HTTP/ChunkedScript][%d] chunkedOK", 200) 85 } 86 87 func (o *ChunkedOK) String() string { 88 return fmt.Sprintf("[GET /HTTP/ChunkedScript][%d] chunkedOK", 200) 89 } 90 91 func (o *ChunkedOK) GetPayload() io.Writer { 92 return o.Payload 93 } 94 95 func (o *ChunkedOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 96 97 // response payload 98 if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 99 return err 100 } 101 102 return nil 103 }