1// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
2
3package restxmlservice
4
5import (
6	"bytes"
7	"fmt"
8	"io"
9	"sync"
10	"sync/atomic"
11	"time"
12
13	"github.com/aws/aws-sdk-go/aws"
14	"github.com/aws/aws-sdk-go/aws/awserr"
15	"github.com/aws/aws-sdk-go/aws/awsutil"
16	"github.com/aws/aws-sdk-go/aws/client"
17	"github.com/aws/aws-sdk-go/aws/request"
18	"github.com/aws/aws-sdk-go/private/protocol"
19	"github.com/aws/aws-sdk-go/private/protocol/eventstream"
20	"github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi"
21	"github.com/aws/aws-sdk-go/private/protocol/rest"
22	"github.com/aws/aws-sdk-go/private/protocol/restxml"
23)
24
25const opEmptyStream = "EmptyStream"
26
27// EmptyStreamRequest generates a "aws/request.Request" representing the
28// client's request for the EmptyStream operation. The "output" return
29// value will be populated with the request's response once the request completes
30// successfully.
31//
32// Use "Send" method on the returned Request to send the API call to the service.
33// the "output" return value is not valid until after Send returns without error.
34//
35// See EmptyStream for more information on using the EmptyStream
36// API call, and error handling.
37//
38// This method is useful when you want to inject custom logic or configuration
39// into the SDK's request lifecycle. Such as custom headers, or retry logic.
40//
41//
42//    // Example sending a request using the EmptyStreamRequest method.
43//    req, resp := client.EmptyStreamRequest(params)
44//
45//    err := req.Send()
46//    if err == nil { // resp is now filled
47//        fmt.Println(resp)
48//    }
49//
50// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/EmptyStream
51func (c *RESTXMLService) EmptyStreamRequest(input *EmptyStreamInput) (req *request.Request, output *EmptyStreamOutput) {
52	op := &request.Operation{
53		Name:       opEmptyStream,
54		HTTPMethod: "POST",
55		HTTPPath:   "/",
56	}
57
58	if input == nil {
59		input = &EmptyStreamInput{}
60	}
61
62	output = &EmptyStreamOutput{}
63	req = c.newRequest(op, input, output)
64	req.Handlers.Send.Swap(client.LogHTTPResponseHandler.Name, client.LogHTTPResponseHeaderHandler)
65	req.Handlers.Unmarshal.Swap(restxml.UnmarshalHandler.Name, rest.UnmarshalHandler)
66	req.Handlers.Unmarshal.PushBack(output.runEventStreamLoop)
67	return
68}
69
70// EmptyStream API operation for REST XML Service.
71//
72// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
73// with awserr.Error's Code and Message methods to get detailed information about
74// the error.
75//
76// See the AWS API reference guide for REST XML Service's
77// API operation EmptyStream for usage and error information.
78// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/EmptyStream
79func (c *RESTXMLService) EmptyStream(input *EmptyStreamInput) (*EmptyStreamOutput, error) {
80	req, out := c.EmptyStreamRequest(input)
81	return out, req.Send()
82}
83
84// EmptyStreamWithContext is the same as EmptyStream with the addition of
85// the ability to pass a context and additional request options.
86//
87// See EmptyStream for details on how to use this API operation.
88//
89// The context must be non-nil and will be used for request cancellation. If
90// the context is nil a panic will occur. In the future the SDK may create
91// sub-contexts for http.Requests. See https://golang.org/pkg/context/
92// for more information on using Contexts.
93func (c *RESTXMLService) EmptyStreamWithContext(ctx aws.Context, input *EmptyStreamInput, opts ...request.Option) (*EmptyStreamOutput, error) {
94	req, out := c.EmptyStreamRequest(input)
95	req.SetContext(ctx)
96	req.ApplyOptions(opts...)
97	return out, req.Send()
98}
99
100const opGetEventStream = "GetEventStream"
101
102// GetEventStreamRequest generates a "aws/request.Request" representing the
103// client's request for the GetEventStream operation. The "output" return
104// value will be populated with the request's response once the request completes
105// successfully.
106//
107// Use "Send" method on the returned Request to send the API call to the service.
108// the "output" return value is not valid until after Send returns without error.
109//
110// See GetEventStream for more information on using the GetEventStream
111// API call, and error handling.
112//
113// This method is useful when you want to inject custom logic or configuration
114// into the SDK's request lifecycle. Such as custom headers, or retry logic.
115//
116//
117//    // Example sending a request using the GetEventStreamRequest method.
118//    req, resp := client.GetEventStreamRequest(params)
119//
120//    err := req.Send()
121//    if err == nil { // resp is now filled
122//        fmt.Println(resp)
123//    }
124//
125// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/GetEventStream
126func (c *RESTXMLService) GetEventStreamRequest(input *GetEventStreamInput) (req *request.Request, output *GetEventStreamOutput) {
127	op := &request.Operation{
128		Name:       opGetEventStream,
129		HTTPMethod: "POST",
130		HTTPPath:   "/",
131	}
132
133	if input == nil {
134		input = &GetEventStreamInput{}
135	}
136
137	output = &GetEventStreamOutput{}
138	req = c.newRequest(op, input, output)
139	req.Handlers.Send.Swap(client.LogHTTPResponseHandler.Name, client.LogHTTPResponseHeaderHandler)
140	req.Handlers.Unmarshal.Swap(restxml.UnmarshalHandler.Name, rest.UnmarshalHandler)
141	req.Handlers.Unmarshal.PushBack(output.runEventStreamLoop)
142	return
143}
144
145// GetEventStream API operation for REST XML Service.
146//
147// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
148// with awserr.Error's Code and Message methods to get detailed information about
149// the error.
150//
151// See the AWS API reference guide for REST XML Service's
152// API operation GetEventStream for usage and error information.
153// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/GetEventStream
154func (c *RESTXMLService) GetEventStream(input *GetEventStreamInput) (*GetEventStreamOutput, error) {
155	req, out := c.GetEventStreamRequest(input)
156	return out, req.Send()
157}
158
159// GetEventStreamWithContext is the same as GetEventStream with the addition of
160// the ability to pass a context and additional request options.
161//
162// See GetEventStream for details on how to use this API operation.
163//
164// The context must be non-nil and will be used for request cancellation. If
165// the context is nil a panic will occur. In the future the SDK may create
166// sub-contexts for http.Requests. See https://golang.org/pkg/context/
167// for more information on using Contexts.
168func (c *RESTXMLService) GetEventStreamWithContext(ctx aws.Context, input *GetEventStreamInput, opts ...request.Option) (*GetEventStreamOutput, error) {
169	req, out := c.GetEventStreamRequest(input)
170	req.SetContext(ctx)
171	req.ApplyOptions(opts...)
172	return out, req.Send()
173}
174
175const opOtherOperation = "OtherOperation"
176
177// OtherOperationRequest generates a "aws/request.Request" representing the
178// client's request for the OtherOperation operation. The "output" return
179// value will be populated with the request's response once the request completes
180// successfully.
181//
182// Use "Send" method on the returned Request to send the API call to the service.
183// the "output" return value is not valid until after Send returns without error.
184//
185// See OtherOperation for more information on using the OtherOperation
186// API call, and error handling.
187//
188// This method is useful when you want to inject custom logic or configuration
189// into the SDK's request lifecycle. Such as custom headers, or retry logic.
190//
191//
192//    // Example sending a request using the OtherOperationRequest method.
193//    req, resp := client.OtherOperationRequest(params)
194//
195//    err := req.Send()
196//    if err == nil { // resp is now filled
197//        fmt.Println(resp)
198//    }
199//
200// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/OtherOperation
201func (c *RESTXMLService) OtherOperationRequest(input *OtherOperationInput) (req *request.Request, output *OtherOperationOutput) {
202	op := &request.Operation{
203		Name:       opOtherOperation,
204		HTTPMethod: "POST",
205		HTTPPath:   "/",
206	}
207
208	if input == nil {
209		input = &OtherOperationInput{}
210	}
211
212	output = &OtherOperationOutput{}
213	req = c.newRequest(op, input, output)
214	req.Handlers.Unmarshal.Swap(restxml.UnmarshalHandler.Name, protocol.UnmarshalDiscardBodyHandler)
215	return
216}
217
218// OtherOperation API operation for REST XML Service.
219//
220// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
221// with awserr.Error's Code and Message methods to get detailed information about
222// the error.
223//
224// See the AWS API reference guide for REST XML Service's
225// API operation OtherOperation for usage and error information.
226//
227// Returned Error Codes:
228//   * ErrCodeExceptionEvent2 "ExceptionEvent2"
229//
230// See also, https://docs.aws.amazon.com/goto/WebAPI/RESTXMLService-0000-00-00/OtherOperation
231func (c *RESTXMLService) OtherOperation(input *OtherOperationInput) (*OtherOperationOutput, error) {
232	req, out := c.OtherOperationRequest(input)
233	return out, req.Send()
234}
235
236// OtherOperationWithContext is the same as OtherOperation with the addition of
237// the ability to pass a context and additional request options.
238//
239// See OtherOperation for details on how to use this API operation.
240//
241// The context must be non-nil and will be used for request cancellation. If
242// the context is nil a panic will occur. In the future the SDK may create
243// sub-contexts for http.Requests. See https://golang.org/pkg/context/
244// for more information on using Contexts.
245func (c *RESTXMLService) OtherOperationWithContext(ctx aws.Context, input *OtherOperationInput, opts ...request.Option) (*OtherOperationOutput, error) {
246	req, out := c.OtherOperationRequest(input)
247	req.SetContext(ctx)
248	req.ApplyOptions(opts...)
249	return out, req.Send()
250}
251
252type EmptyEvent struct {
253	_ struct{} `locationName:"EmptyEvent" type:"structure"`
254}
255
256// String returns the string representation
257func (s EmptyEvent) String() string {
258	return awsutil.Prettify(s)
259}
260
261// GoString returns the string representation
262func (s EmptyEvent) GoString() string {
263	return s.String()
264}
265
266// The EmptyEvent is and event in the EventStream group of events.
267func (s *EmptyEvent) eventEventStream() {}
268
269// UnmarshalEvent unmarshals the EventStream Message into the EmptyEvent value.
270// This method is only used internally within the SDK's EventStream handling.
271func (s *EmptyEvent) UnmarshalEvent(
272	payloadUnmarshaler protocol.PayloadUnmarshaler,
273	msg eventstream.Message,
274) error {
275	return nil
276}
277
278// EmptyStreamEventStream provides handling of EventStreams for
279// the EmptyStream API.
280//
281// Use this type to receive EmptyEventStream events. The events
282// can be read from the Events channel member.
283//
284// The events that can be received are:
285//
286type EmptyStreamEventStream struct {
287	// Reader is the EventStream reader for the EmptyEventStream
288	// events. This value is automatically set by the SDK when the API call is made
289	// Use this member when unit testing your code with the SDK to mock out the
290	// EventStream Reader.
291	//
292	// Must not be nil.
293	Reader EmptyStreamEventStreamReader
294
295	// StreamCloser is the io.Closer for the EventStream connection. For HTTP
296	// EventStream this is the response Body. The stream will be closed when
297	// the Close method of the EventStream is called.
298	StreamCloser io.Closer
299}
300
301// Close closes the EventStream. This will also cause the Events channel to be
302// closed. You can use the closing of the Events channel to terminate your
303// application's read from the API's EventStream.
304//
305// Will close the underlying EventStream reader. For EventStream over HTTP
306// connection this will also close the HTTP connection.
307//
308// Close must be called when done using the EventStream API. Not calling Close
309// may result in resource leaks.
310func (es *EmptyStreamEventStream) Close() (err error) {
311	es.Reader.Close()
312	return es.Err()
313}
314
315// Err returns any error that occurred while reading EventStream Events from
316// the service API's response. Returns nil if there were no errors.
317func (es *EmptyStreamEventStream) Err() error {
318	if err := es.Reader.Err(); err != nil {
319		return err
320	}
321	es.StreamCloser.Close()
322
323	return nil
324}
325
326// Events returns a channel to read EventStream Events from the
327// EmptyStream API.
328//
329// These events are:
330//
331func (es *EmptyStreamEventStream) Events() <-chan EmptyEventStreamEvent {
332	return es.Reader.Events()
333}
334
335// EmptyEventStreamEvent groups together all EventStream
336// events read from the EmptyStream API.
337//
338// These events are:
339//
340type EmptyEventStreamEvent interface {
341	eventEmptyEventStream()
342}
343
344// EmptyStreamEventStreamReader provides the interface for reading EventStream
345// Events from the EmptyStream API. The
346// default implementation for this interface will be EmptyStreamEventStream.
347//
348// The reader's Close method must allow multiple concurrent calls.
349//
350// These events are:
351//
352type EmptyStreamEventStreamReader interface {
353	// Returns a channel of events as they are read from the event stream.
354	Events() <-chan EmptyEventStreamEvent
355
356	// Close will close the underlying event stream reader. For event stream over
357	// HTTP this will also close the HTTP connection.
358	Close() error
359
360	// Returns any error that has occurred while reading from the event stream.
361	Err() error
362}
363
364type readEmptyStreamEventStream struct {
365	eventReader *eventstreamapi.EventReader
366	stream      chan EmptyEventStreamEvent
367	errVal      atomic.Value
368
369	done      chan struct{}
370	closeOnce sync.Once
371}
372
373func newReadEmptyStreamEventStream(
374	reader io.ReadCloser,
375	unmarshalers request.HandlerList,
376	logger aws.Logger,
377	logLevel aws.LogLevelType,
378) *readEmptyStreamEventStream {
379	r := &readEmptyStreamEventStream{
380		stream: make(chan EmptyEventStreamEvent),
381		done:   make(chan struct{}),
382	}
383
384	r.eventReader = eventstreamapi.NewEventReader(
385		reader,
386		protocol.HandlerPayloadUnmarshal{
387			Unmarshalers: unmarshalers,
388		},
389		r.unmarshalerForEventType,
390	)
391	r.eventReader.UseLogger(logger, logLevel)
392
393	return r
394}
395
396// Close will close the underlying event stream reader. For EventStream over
397// HTTP this will also close the HTTP connection.
398func (r *readEmptyStreamEventStream) Close() error {
399	r.closeOnce.Do(r.safeClose)
400
401	return r.Err()
402}
403
404func (r *readEmptyStreamEventStream) safeClose() {
405	close(r.done)
406	err := r.eventReader.Close()
407	if err != nil {
408		r.errVal.Store(err)
409	}
410}
411
412func (r *readEmptyStreamEventStream) Err() error {
413	if v := r.errVal.Load(); v != nil {
414		return v.(error)
415	}
416
417	return nil
418}
419
420func (r *readEmptyStreamEventStream) Events() <-chan EmptyEventStreamEvent {
421	return r.stream
422}
423
424func (r *readEmptyStreamEventStream) readEventStream() {
425	defer close(r.stream)
426
427	for {
428		event, err := r.eventReader.ReadEvent()
429		if err != nil {
430			if err == io.EOF {
431				return
432			}
433			select {
434			case <-r.done:
435				// If closed already ignore the error
436				return
437			default:
438			}
439			r.errVal.Store(err)
440			return
441		}
442
443		select {
444		case r.stream <- event.(EmptyEventStreamEvent):
445		case <-r.done:
446			return
447		}
448	}
449}
450
451func (r *readEmptyStreamEventStream) unmarshalerForEventType(
452	eventType string,
453) (eventstreamapi.Unmarshaler, error) {
454	switch eventType {
455	default:
456		return nil, awserr.New(
457			request.ErrCodeSerialization,
458			fmt.Sprintf("unknown event type name, %s, for EmptyStreamEventStream", eventType),
459			nil,
460		)
461	}
462}
463
464type EmptyStreamInput struct {
465	_ struct{} `type:"structure"`
466}
467
468// String returns the string representation
469func (s EmptyStreamInput) String() string {
470	return awsutil.Prettify(s)
471}
472
473// GoString returns the string representation
474func (s EmptyStreamInput) GoString() string {
475	return s.String()
476}
477
478type EmptyStreamOutput struct {
479	_ struct{} `type:"structure"`
480
481	// Use EventStream to use the API's stream.
482	EventStream *EmptyStreamEventStream `type:"structure"`
483}
484
485// String returns the string representation
486func (s EmptyStreamOutput) String() string {
487	return awsutil.Prettify(s)
488}
489
490// GoString returns the string representation
491func (s EmptyStreamOutput) GoString() string {
492	return s.String()
493}
494
495// SetEventStream sets the EventStream field's value.
496func (s *EmptyStreamOutput) SetEventStream(v *EmptyStreamEventStream) *EmptyStreamOutput {
497	s.EventStream = v
498	return s
499}
500
501func (s *EmptyStreamOutput) runEventStreamLoop(r *request.Request) {
502	if r.Error != nil {
503		return
504	}
505	reader := newReadEmptyStreamEventStream(
506		r.HTTPResponse.Body,
507		r.Handlers.UnmarshalStream,
508		r.Config.Logger,
509		r.Config.LogLevel.Value(),
510	)
511	go reader.readEventStream()
512
513	eventStream := &EmptyStreamEventStream{
514		StreamCloser: r.HTTPResponse.Body,
515		Reader:       reader,
516	}
517	s.EventStream = eventStream
518}
519
520type ExceptionEvent struct {
521	_ struct{} `locationName:"ExceptionEvent" type:"structure"`
522
523	IntVal *int64 `type:"integer"`
524
525	Message_ *string `locationName:"message" type:"string"`
526}
527
528// String returns the string representation
529func (s ExceptionEvent) String() string {
530	return awsutil.Prettify(s)
531}
532
533// GoString returns the string representation
534func (s ExceptionEvent) GoString() string {
535	return s.String()
536}
537
538// The ExceptionEvent is and event in the EventStream group of events.
539func (s *ExceptionEvent) eventEventStream() {}
540
541// UnmarshalEvent unmarshals the EventStream Message into the ExceptionEvent value.
542// This method is only used internally within the SDK's EventStream handling.
543func (s *ExceptionEvent) UnmarshalEvent(
544	payloadUnmarshaler protocol.PayloadUnmarshaler,
545	msg eventstream.Message,
546) error {
547	if err := payloadUnmarshaler.UnmarshalPayload(
548		bytes.NewReader(msg.Payload), s,
549	); err != nil {
550		return err
551	}
552	return nil
553}
554
555// Code returns the exception type name.
556func (s ExceptionEvent) Code() string {
557	return "ExceptionEvent"
558}
559
560// Message returns the exception's message.
561func (s ExceptionEvent) Message() string {
562	return *s.Message_
563}
564
565// OrigErr always returns nil, satisfies awserr.Error interface.
566func (s ExceptionEvent) OrigErr() error {
567	return nil
568}
569
570func (s ExceptionEvent) Error() string {
571	return fmt.Sprintf("%s: %s", s.Code(), s.Message())
572}
573
574type ExceptionEvent2 struct {
575	_ struct{} `locationName:"ExceptionEvent2" type:"structure"`
576}
577
578// String returns the string representation
579func (s ExceptionEvent2) String() string {
580	return awsutil.Prettify(s)
581}
582
583// GoString returns the string representation
584func (s ExceptionEvent2) GoString() string {
585	return s.String()
586}
587
588// The ExceptionEvent2 is and event in the EventStream group of events.
589func (s *ExceptionEvent2) eventEventStream() {}
590
591// UnmarshalEvent unmarshals the EventStream Message into the ExceptionEvent2 value.
592// This method is only used internally within the SDK's EventStream handling.
593func (s *ExceptionEvent2) UnmarshalEvent(
594	payloadUnmarshaler protocol.PayloadUnmarshaler,
595	msg eventstream.Message,
596) error {
597	return nil
598}
599
600// Code returns the exception type name.
601func (s ExceptionEvent2) Code() string {
602	return "ExceptionEvent2"
603}
604
605// Message returns the exception's message.
606func (s ExceptionEvent2) Message() string {
607	return ""
608}
609
610// OrigErr always returns nil, satisfies awserr.Error interface.
611func (s ExceptionEvent2) OrigErr() error {
612	return nil
613}
614
615func (s ExceptionEvent2) Error() string {
616	return fmt.Sprintf("%s: %s", s.Code(), s.Message())
617}
618
619type ExplicitPayloadEvent struct {
620	_ struct{} `locationName:"ExplicitPayloadEvent" type:"structure" payload:"NestedVal"`
621
622	LongVal *int64 `location:"header" type:"long"`
623
624	NestedVal *NestedShape `locationName:"NestedVal" type:"structure"`
625
626	StringVal *string `location:"header" type:"string"`
627}
628
629// String returns the string representation
630func (s ExplicitPayloadEvent) String() string {
631	return awsutil.Prettify(s)
632}
633
634// GoString returns the string representation
635func (s ExplicitPayloadEvent) GoString() string {
636	return s.String()
637}
638
639// SetLongVal sets the LongVal field's value.
640func (s *ExplicitPayloadEvent) SetLongVal(v int64) *ExplicitPayloadEvent {
641	s.LongVal = &v
642	return s
643}
644
645// SetNestedVal sets the NestedVal field's value.
646func (s *ExplicitPayloadEvent) SetNestedVal(v *NestedShape) *ExplicitPayloadEvent {
647	s.NestedVal = v
648	return s
649}
650
651// SetStringVal sets the StringVal field's value.
652func (s *ExplicitPayloadEvent) SetStringVal(v string) *ExplicitPayloadEvent {
653	s.StringVal = &v
654	return s
655}
656
657// The ExplicitPayloadEvent is and event in the EventStream group of events.
658func (s *ExplicitPayloadEvent) eventEventStream() {}
659
660// UnmarshalEvent unmarshals the EventStream Message into the ExplicitPayloadEvent value.
661// This method is only used internally within the SDK's EventStream handling.
662func (s *ExplicitPayloadEvent) UnmarshalEvent(
663	payloadUnmarshaler protocol.PayloadUnmarshaler,
664	msg eventstream.Message,
665) error {
666	if hv := msg.Headers.Get("LongVal"); hv != nil {
667		v := hv.Get().(int64)
668		s.LongVal = &v
669	}
670	if hv := msg.Headers.Get("StringVal"); hv != nil {
671		v := hv.Get().(string)
672		s.StringVal = &v
673	}
674	if err := payloadUnmarshaler.UnmarshalPayload(
675		bytes.NewReader(msg.Payload), s,
676	); err != nil {
677		return err
678	}
679	return nil
680}
681
682// GetEventStreamEventStream provides handling of EventStreams for
683// the GetEventStream API.
684//
685// Use this type to receive EventStream events. The events
686// can be read from the Events channel member.
687//
688// The events that can be received are:
689//
690//     * EmptyEvent
691//     * ExplicitPayloadEvent
692//     * HeaderOnlyEvent
693//     * ImplicitPayloadEvent
694//     * PayloadOnlyEvent
695//     * PayloadOnlyBlobEvent
696//     * PayloadOnlyStringEvent
697type GetEventStreamEventStream struct {
698	// Reader is the EventStream reader for the EventStream
699	// events. This value is automatically set by the SDK when the API call is made
700	// Use this member when unit testing your code with the SDK to mock out the
701	// EventStream Reader.
702	//
703	// Must not be nil.
704	Reader GetEventStreamEventStreamReader
705
706	// StreamCloser is the io.Closer for the EventStream connection. For HTTP
707	// EventStream this is the response Body. The stream will be closed when
708	// the Close method of the EventStream is called.
709	StreamCloser io.Closer
710}
711
712// Close closes the EventStream. This will also cause the Events channel to be
713// closed. You can use the closing of the Events channel to terminate your
714// application's read from the API's EventStream.
715//
716// Will close the underlying EventStream reader. For EventStream over HTTP
717// connection this will also close the HTTP connection.
718//
719// Close must be called when done using the EventStream API. Not calling Close
720// may result in resource leaks.
721func (es *GetEventStreamEventStream) Close() (err error) {
722	es.Reader.Close()
723	return es.Err()
724}
725
726// Err returns any error that occurred while reading EventStream Events from
727// the service API's response. Returns nil if there were no errors.
728func (es *GetEventStreamEventStream) Err() error {
729	if err := es.Reader.Err(); err != nil {
730		return err
731	}
732	es.StreamCloser.Close()
733
734	return nil
735}
736
737// Events returns a channel to read EventStream Events from the
738// GetEventStream API.
739//
740// These events are:
741//
742//     * EmptyEvent
743//     * ExplicitPayloadEvent
744//     * HeaderOnlyEvent
745//     * ImplicitPayloadEvent
746//     * PayloadOnlyEvent
747//     * PayloadOnlyBlobEvent
748//     * PayloadOnlyStringEvent
749func (es *GetEventStreamEventStream) Events() <-chan EventStreamEvent {
750	return es.Reader.Events()
751}
752
753// EventStreamEvent groups together all EventStream
754// events read from the GetEventStream API.
755//
756// These events are:
757//
758//     * EmptyEvent
759//     * ExplicitPayloadEvent
760//     * HeaderOnlyEvent
761//     * ImplicitPayloadEvent
762//     * PayloadOnlyEvent
763//     * PayloadOnlyBlobEvent
764//     * PayloadOnlyStringEvent
765type EventStreamEvent interface {
766	eventEventStream()
767}
768
769// GetEventStreamEventStreamReader provides the interface for reading EventStream
770// Events from the GetEventStream API. The
771// default implementation for this interface will be GetEventStreamEventStream.
772//
773// The reader's Close method must allow multiple concurrent calls.
774//
775// These events are:
776//
777//     * EmptyEvent
778//     * ExplicitPayloadEvent
779//     * HeaderOnlyEvent
780//     * ImplicitPayloadEvent
781//     * PayloadOnlyEvent
782//     * PayloadOnlyBlobEvent
783//     * PayloadOnlyStringEvent
784type GetEventStreamEventStreamReader interface {
785	// Returns a channel of events as they are read from the event stream.
786	Events() <-chan EventStreamEvent
787
788	// Close will close the underlying event stream reader. For event stream over
789	// HTTP this will also close the HTTP connection.
790	Close() error
791
792	// Returns any error that has occurred while reading from the event stream.
793	Err() error
794}
795
796type readGetEventStreamEventStream struct {
797	eventReader *eventstreamapi.EventReader
798	stream      chan EventStreamEvent
799	errVal      atomic.Value
800
801	done      chan struct{}
802	closeOnce sync.Once
803}
804
805func newReadGetEventStreamEventStream(
806	reader io.ReadCloser,
807	unmarshalers request.HandlerList,
808	logger aws.Logger,
809	logLevel aws.LogLevelType,
810) *readGetEventStreamEventStream {
811	r := &readGetEventStreamEventStream{
812		stream: make(chan EventStreamEvent),
813		done:   make(chan struct{}),
814	}
815
816	r.eventReader = eventstreamapi.NewEventReader(
817		reader,
818		protocol.HandlerPayloadUnmarshal{
819			Unmarshalers: unmarshalers,
820		},
821		r.unmarshalerForEventType,
822	)
823	r.eventReader.UseLogger(logger, logLevel)
824
825	return r
826}
827
828// Close will close the underlying event stream reader. For EventStream over
829// HTTP this will also close the HTTP connection.
830func (r *readGetEventStreamEventStream) Close() error {
831	r.closeOnce.Do(r.safeClose)
832
833	return r.Err()
834}
835
836func (r *readGetEventStreamEventStream) safeClose() {
837	close(r.done)
838	err := r.eventReader.Close()
839	if err != nil {
840		r.errVal.Store(err)
841	}
842}
843
844func (r *readGetEventStreamEventStream) Err() error {
845	if v := r.errVal.Load(); v != nil {
846		return v.(error)
847	}
848
849	return nil
850}
851
852func (r *readGetEventStreamEventStream) Events() <-chan EventStreamEvent {
853	return r.stream
854}
855
856func (r *readGetEventStreamEventStream) readEventStream() {
857	defer close(r.stream)
858
859	for {
860		event, err := r.eventReader.ReadEvent()
861		if err != nil {
862			if err == io.EOF {
863				return
864			}
865			select {
866			case <-r.done:
867				// If closed already ignore the error
868				return
869			default:
870			}
871			r.errVal.Store(err)
872			return
873		}
874
875		select {
876		case r.stream <- event.(EventStreamEvent):
877		case <-r.done:
878			return
879		}
880	}
881}
882
883func (r *readGetEventStreamEventStream) unmarshalerForEventType(
884	eventType string,
885) (eventstreamapi.Unmarshaler, error) {
886	switch eventType {
887	case "Empty":
888		return &EmptyEvent{}, nil
889
890	case "ExplicitPayload":
891		return &ExplicitPayloadEvent{}, nil
892
893	case "Headers":
894		return &HeaderOnlyEvent{}, nil
895
896	case "ImplicitPayload":
897		return &ImplicitPayloadEvent{}, nil
898
899	case "PayloadOnly":
900		return &PayloadOnlyEvent{}, nil
901
902	case "PayloadOnlyBlob":
903		return &PayloadOnlyBlobEvent{}, nil
904
905	case "PayloadOnlyString":
906		return &PayloadOnlyStringEvent{}, nil
907
908	case "Exception":
909		return &ExceptionEvent{}, nil
910
911	case "Exception2":
912		return &ExceptionEvent2{}, nil
913	default:
914		return nil, awserr.New(
915			request.ErrCodeSerialization,
916			fmt.Sprintf("unknown event type name, %s, for GetEventStreamEventStream", eventType),
917			nil,
918		)
919	}
920}
921
922type GetEventStreamInput struct {
923	_ struct{} `type:"structure"`
924
925	InputVal *string `type:"string"`
926}
927
928// String returns the string representation
929func (s GetEventStreamInput) String() string {
930	return awsutil.Prettify(s)
931}
932
933// GoString returns the string representation
934func (s GetEventStreamInput) GoString() string {
935	return s.String()
936}
937
938// SetInputVal sets the InputVal field's value.
939func (s *GetEventStreamInput) SetInputVal(v string) *GetEventStreamInput {
940	s.InputVal = &v
941	return s
942}
943
944type GetEventStreamOutput struct {
945	_ struct{} `type:"structure"`
946
947	// Use EventStream to use the API's stream.
948	EventStream *GetEventStreamEventStream `type:"structure"`
949
950	IntVal *int64 `type:"integer"`
951
952	StrVal *string `type:"string"`
953}
954
955// String returns the string representation
956func (s GetEventStreamOutput) String() string {
957	return awsutil.Prettify(s)
958}
959
960// GoString returns the string representation
961func (s GetEventStreamOutput) GoString() string {
962	return s.String()
963}
964
965// SetEventStream sets the EventStream field's value.
966func (s *GetEventStreamOutput) SetEventStream(v *GetEventStreamEventStream) *GetEventStreamOutput {
967	s.EventStream = v
968	return s
969}
970
971// SetIntVal sets the IntVal field's value.
972func (s *GetEventStreamOutput) SetIntVal(v int64) *GetEventStreamOutput {
973	s.IntVal = &v
974	return s
975}
976
977// SetStrVal sets the StrVal field's value.
978func (s *GetEventStreamOutput) SetStrVal(v string) *GetEventStreamOutput {
979	s.StrVal = &v
980	return s
981}
982
983func (s *GetEventStreamOutput) runEventStreamLoop(r *request.Request) {
984	if r.Error != nil {
985		return
986	}
987	reader := newReadGetEventStreamEventStream(
988		r.HTTPResponse.Body,
989		r.Handlers.UnmarshalStream,
990		r.Config.Logger,
991		r.Config.LogLevel.Value(),
992	)
993	go reader.readEventStream()
994
995	eventStream := &GetEventStreamEventStream{
996		StreamCloser: r.HTTPResponse.Body,
997		Reader:       reader,
998	}
999	s.EventStream = eventStream
1000}
1001
1002type HeaderOnlyEvent struct {
1003	_ struct{} `locationName:"HeaderOnlyEvent" type:"structure"`
1004
1005	// BlobVal is automatically base64 encoded/decoded by the SDK.
1006	BlobVal []byte `location:"header" type:"blob"`
1007
1008	BoolVal *bool `location:"header" type:"boolean"`
1009
1010	ByteVal *int64 `location:"header" type:"byte"`
1011
1012	IntegerVal *int64 `location:"header" type:"integer"`
1013
1014	LongVal *int64 `location:"header" type:"long"`
1015
1016	ShortVal *int64 `location:"header" type:"short"`
1017
1018	StringVal *string `location:"header" type:"string"`
1019
1020	TimeVal *time.Time `location:"header" type:"timestamp"`
1021}
1022
1023// String returns the string representation
1024func (s HeaderOnlyEvent) String() string {
1025	return awsutil.Prettify(s)
1026}
1027
1028// GoString returns the string representation
1029func (s HeaderOnlyEvent) GoString() string {
1030	return s.String()
1031}
1032
1033// SetBlobVal sets the BlobVal field's value.
1034func (s *HeaderOnlyEvent) SetBlobVal(v []byte) *HeaderOnlyEvent {
1035	s.BlobVal = v
1036	return s
1037}
1038
1039// SetBoolVal sets the BoolVal field's value.
1040func (s *HeaderOnlyEvent) SetBoolVal(v bool) *HeaderOnlyEvent {
1041	s.BoolVal = &v
1042	return s
1043}
1044
1045// SetByteVal sets the ByteVal field's value.
1046func (s *HeaderOnlyEvent) SetByteVal(v int64) *HeaderOnlyEvent {
1047	s.ByteVal = &v
1048	return s
1049}
1050
1051// SetIntegerVal sets the IntegerVal field's value.
1052func (s *HeaderOnlyEvent) SetIntegerVal(v int64) *HeaderOnlyEvent {
1053	s.IntegerVal = &v
1054	return s
1055}
1056
1057// SetLongVal sets the LongVal field's value.
1058func (s *HeaderOnlyEvent) SetLongVal(v int64) *HeaderOnlyEvent {
1059	s.LongVal = &v
1060	return s
1061}
1062
1063// SetShortVal sets the ShortVal field's value.
1064func (s *HeaderOnlyEvent) SetShortVal(v int64) *HeaderOnlyEvent {
1065	s.ShortVal = &v
1066	return s
1067}
1068
1069// SetStringVal sets the StringVal field's value.
1070func (s *HeaderOnlyEvent) SetStringVal(v string) *HeaderOnlyEvent {
1071	s.StringVal = &v
1072	return s
1073}
1074
1075// SetTimeVal sets the TimeVal field's value.
1076func (s *HeaderOnlyEvent) SetTimeVal(v time.Time) *HeaderOnlyEvent {
1077	s.TimeVal = &v
1078	return s
1079}
1080
1081// The HeaderOnlyEvent is and event in the EventStream group of events.
1082func (s *HeaderOnlyEvent) eventEventStream() {}
1083
1084// UnmarshalEvent unmarshals the EventStream Message into the HeaderOnlyEvent value.
1085// This method is only used internally within the SDK's EventStream handling.
1086func (s *HeaderOnlyEvent) UnmarshalEvent(
1087	payloadUnmarshaler protocol.PayloadUnmarshaler,
1088	msg eventstream.Message,
1089) error {
1090	if hv := msg.Headers.Get("BlobVal"); hv != nil {
1091		v := hv.Get().([]byte)
1092		s.BlobVal = v
1093	}
1094	if hv := msg.Headers.Get("BoolVal"); hv != nil {
1095		v := hv.Get().(bool)
1096		s.BoolVal = &v
1097	}
1098	if hv := msg.Headers.Get("ByteVal"); hv != nil {
1099		v := hv.Get().(int8)
1100		m := int64(v)
1101		s.ByteVal = &m
1102	}
1103	if hv := msg.Headers.Get("IntegerVal"); hv != nil {
1104		v := hv.Get().(int32)
1105		m := int64(v)
1106		s.IntegerVal = &m
1107	}
1108	if hv := msg.Headers.Get("LongVal"); hv != nil {
1109		v := hv.Get().(int64)
1110		s.LongVal = &v
1111	}
1112	if hv := msg.Headers.Get("ShortVal"); hv != nil {
1113		v := hv.Get().(int16)
1114		m := int64(v)
1115		s.ShortVal = &m
1116	}
1117	if hv := msg.Headers.Get("StringVal"); hv != nil {
1118		v := hv.Get().(string)
1119		s.StringVal = &v
1120	}
1121	if hv := msg.Headers.Get("TimeVal"); hv != nil {
1122		v := hv.Get().(time.Time)
1123		s.TimeVal = &v
1124	}
1125	return nil
1126}
1127
1128type ImplicitPayloadEvent struct {
1129	_ struct{} `locationName:"ImplicitPayloadEvent" type:"structure"`
1130
1131	ByteVal *int64 `location:"header" type:"byte"`
1132
1133	IntegerVal *int64 `type:"integer"`
1134
1135	ShortVal *int64 `type:"short"`
1136}
1137
1138// String returns the string representation
1139func (s ImplicitPayloadEvent) String() string {
1140	return awsutil.Prettify(s)
1141}
1142
1143// GoString returns the string representation
1144func (s ImplicitPayloadEvent) GoString() string {
1145	return s.String()
1146}
1147
1148// SetByteVal sets the ByteVal field's value.
1149func (s *ImplicitPayloadEvent) SetByteVal(v int64) *ImplicitPayloadEvent {
1150	s.ByteVal = &v
1151	return s
1152}
1153
1154// SetIntegerVal sets the IntegerVal field's value.
1155func (s *ImplicitPayloadEvent) SetIntegerVal(v int64) *ImplicitPayloadEvent {
1156	s.IntegerVal = &v
1157	return s
1158}
1159
1160// SetShortVal sets the ShortVal field's value.
1161func (s *ImplicitPayloadEvent) SetShortVal(v int64) *ImplicitPayloadEvent {
1162	s.ShortVal = &v
1163	return s
1164}
1165
1166// The ImplicitPayloadEvent is and event in the EventStream group of events.
1167func (s *ImplicitPayloadEvent) eventEventStream() {}
1168
1169// UnmarshalEvent unmarshals the EventStream Message into the ImplicitPayloadEvent value.
1170// This method is only used internally within the SDK's EventStream handling.
1171func (s *ImplicitPayloadEvent) UnmarshalEvent(
1172	payloadUnmarshaler protocol.PayloadUnmarshaler,
1173	msg eventstream.Message,
1174) error {
1175	if hv := msg.Headers.Get("ByteVal"); hv != nil {
1176		v := hv.Get().(int8)
1177		m := int64(v)
1178		s.ByteVal = &m
1179	}
1180	if err := payloadUnmarshaler.UnmarshalPayload(
1181		bytes.NewReader(msg.Payload), s,
1182	); err != nil {
1183		return err
1184	}
1185	return nil
1186}
1187
1188type NestedShape struct {
1189	_ struct{} `type:"structure"`
1190
1191	IntVal *int64 `type:"integer"`
1192
1193	StrVal *string `type:"string"`
1194}
1195
1196// String returns the string representation
1197func (s NestedShape) String() string {
1198	return awsutil.Prettify(s)
1199}
1200
1201// GoString returns the string representation
1202func (s NestedShape) GoString() string {
1203	return s.String()
1204}
1205
1206// SetIntVal sets the IntVal field's value.
1207func (s *NestedShape) SetIntVal(v int64) *NestedShape {
1208	s.IntVal = &v
1209	return s
1210}
1211
1212// SetStrVal sets the StrVal field's value.
1213func (s *NestedShape) SetStrVal(v string) *NestedShape {
1214	s.StrVal = &v
1215	return s
1216}
1217
1218type OtherOperationInput struct {
1219	_ struct{} `type:"structure"`
1220}
1221
1222// String returns the string representation
1223func (s OtherOperationInput) String() string {
1224	return awsutil.Prettify(s)
1225}
1226
1227// GoString returns the string representation
1228func (s OtherOperationInput) GoString() string {
1229	return s.String()
1230}
1231
1232type OtherOperationOutput struct {
1233	_ struct{} `type:"structure"`
1234}
1235
1236// String returns the string representation
1237func (s OtherOperationOutput) String() string {
1238	return awsutil.Prettify(s)
1239}
1240
1241// GoString returns the string representation
1242func (s OtherOperationOutput) GoString() string {
1243	return s.String()
1244}
1245
1246type PayloadOnlyBlobEvent struct {
1247	_ struct{} `locationName:"PayloadOnlyBlobEvent" type:"structure" payload:"BlobPayload"`
1248
1249	// BlobPayload is automatically base64 encoded/decoded by the SDK.
1250	BlobPayload []byte `type:"blob"`
1251}
1252
1253// String returns the string representation
1254func (s PayloadOnlyBlobEvent) String() string {
1255	return awsutil.Prettify(s)
1256}
1257
1258// GoString returns the string representation
1259func (s PayloadOnlyBlobEvent) GoString() string {
1260	return s.String()
1261}
1262
1263// SetBlobPayload sets the BlobPayload field's value.
1264func (s *PayloadOnlyBlobEvent) SetBlobPayload(v []byte) *PayloadOnlyBlobEvent {
1265	s.BlobPayload = v
1266	return s
1267}
1268
1269// The PayloadOnlyBlobEvent is and event in the EventStream group of events.
1270func (s *PayloadOnlyBlobEvent) eventEventStream() {}
1271
1272// UnmarshalEvent unmarshals the EventStream Message into the PayloadOnlyBlobEvent value.
1273// This method is only used internally within the SDK's EventStream handling.
1274func (s *PayloadOnlyBlobEvent) UnmarshalEvent(
1275	payloadUnmarshaler protocol.PayloadUnmarshaler,
1276	msg eventstream.Message,
1277) error {
1278	s.BlobPayload = make([]byte, len(msg.Payload))
1279	copy(s.BlobPayload, msg.Payload)
1280	return nil
1281}
1282
1283type PayloadOnlyEvent struct {
1284	_ struct{} `locationName:"PayloadOnlyEvent" type:"structure" payload:"NestedVal"`
1285
1286	NestedVal *NestedShape `locationName:"NestedVal" type:"structure"`
1287}
1288
1289// String returns the string representation
1290func (s PayloadOnlyEvent) String() string {
1291	return awsutil.Prettify(s)
1292}
1293
1294// GoString returns the string representation
1295func (s PayloadOnlyEvent) GoString() string {
1296	return s.String()
1297}
1298
1299// SetNestedVal sets the NestedVal field's value.
1300func (s *PayloadOnlyEvent) SetNestedVal(v *NestedShape) *PayloadOnlyEvent {
1301	s.NestedVal = v
1302	return s
1303}
1304
1305// The PayloadOnlyEvent is and event in the EventStream group of events.
1306func (s *PayloadOnlyEvent) eventEventStream() {}
1307
1308// UnmarshalEvent unmarshals the EventStream Message into the PayloadOnlyEvent value.
1309// This method is only used internally within the SDK's EventStream handling.
1310func (s *PayloadOnlyEvent) UnmarshalEvent(
1311	payloadUnmarshaler protocol.PayloadUnmarshaler,
1312	msg eventstream.Message,
1313) error {
1314	if err := payloadUnmarshaler.UnmarshalPayload(
1315		bytes.NewReader(msg.Payload), s,
1316	); err != nil {
1317		return err
1318	}
1319	return nil
1320}
1321
1322type PayloadOnlyStringEvent struct {
1323	_ struct{} `locationName:"PayloadOnlyStringEvent" type:"structure" payload:"StringPayload"`
1324
1325	StringPayload *string `locationName:"StringPayload" type:"string"`
1326}
1327
1328// String returns the string representation
1329func (s PayloadOnlyStringEvent) String() string {
1330	return awsutil.Prettify(s)
1331}
1332
1333// GoString returns the string representation
1334func (s PayloadOnlyStringEvent) GoString() string {
1335	return s.String()
1336}
1337
1338// SetStringPayload sets the StringPayload field's value.
1339func (s *PayloadOnlyStringEvent) SetStringPayload(v string) *PayloadOnlyStringEvent {
1340	s.StringPayload = &v
1341	return s
1342}
1343
1344// The PayloadOnlyStringEvent is and event in the EventStream group of events.
1345func (s *PayloadOnlyStringEvent) eventEventStream() {}
1346
1347// UnmarshalEvent unmarshals the EventStream Message into the PayloadOnlyStringEvent value.
1348// This method is only used internally within the SDK's EventStream handling.
1349func (s *PayloadOnlyStringEvent) UnmarshalEvent(
1350	payloadUnmarshaler protocol.PayloadUnmarshaler,
1351	msg eventstream.Message,
1352) error {
1353	s.StringPayload = aws.String(string(msg.Payload))
1354	return nil
1355}
1356