|
| 1 | +package polly |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "fmt" |
| 7 | + "github.com/aws/aws-sdk-go-v2/aws/protocol/query" |
| 8 | + "github.com/aws/smithy-go" |
| 9 | + "github.com/aws/smithy-go/middleware" |
| 10 | + smithyhttp "github.com/aws/smithy-go/transport/http" |
| 11 | +) |
| 12 | + |
| 13 | +// AddPresignSynthesizeSpeechMiddleware adds presignOpSynthesizeSpeechInput into middleware stack to |
| 14 | +// parse SynthesizeSpeechInput into request stream |
| 15 | +func AddPresignSynthesizeSpeechMiddleware(stack *middleware.Stack) error { |
| 16 | + return stack.Serialize.Insert(&presignOpSynthesizeSpeechInput{}, "Query:AsGetRequest", middleware.Before) |
| 17 | +} |
| 18 | + |
| 19 | +// presignOpSynthesizeSpeechInput encodes SynthesizeSpeechInput into url format |
| 20 | +// query string and put that into request stream for later presign-url build |
| 21 | +type presignOpSynthesizeSpeechInput struct { |
| 22 | +} |
| 23 | + |
| 24 | +func (*presignOpSynthesizeSpeechInput) ID() string { |
| 25 | + return "PresignSerializer" |
| 26 | +} |
| 27 | + |
| 28 | +func (m *presignOpSynthesizeSpeechInput) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( |
| 29 | + out middleware.SerializeOutput, metadata middleware.Metadata, err error, |
| 30 | +) { |
| 31 | + request, ok := in.Request.(*smithyhttp.Request) |
| 32 | + if !ok { |
| 33 | + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)} |
| 34 | + } |
| 35 | + |
| 36 | + input, ok := in.Parameters.(*SynthesizeSpeechInput) |
| 37 | + _ = input |
| 38 | + if !ok { |
| 39 | + return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)} |
| 40 | + } |
| 41 | + |
| 42 | + bodyWriter := bytes.NewBuffer(nil) |
| 43 | + bodyEncoder := query.NewEncoder(bodyWriter) |
| 44 | + |
| 45 | + if err := presignSerializeOpDocumentSynthesizeSpeechInput(input, bodyEncoder.Value); err != nil { |
| 46 | + return out, metadata, &smithy.SerializationError{Err: err} |
| 47 | + } |
| 48 | + |
| 49 | + err = bodyEncoder.Encode() |
| 50 | + if err != nil { |
| 51 | + return out, metadata, &smithy.SerializationError{Err: err} |
| 52 | + } |
| 53 | + |
| 54 | + if request, err = request.SetStream(bytes.NewReader(bodyWriter.Bytes())); err != nil { |
| 55 | + return out, metadata, &smithy.SerializationError{Err: err} |
| 56 | + } |
| 57 | + |
| 58 | + in.Request = request |
| 59 | + |
| 60 | + return next.HandleSerialize(ctx, in) |
| 61 | +} |
| 62 | + |
| 63 | +func presignSerializeOpDocumentSynthesizeSpeechInput(v *SynthesizeSpeechInput, value query.Value) error { |
| 64 | + object := value.Object() |
| 65 | + _ = object |
| 66 | + |
| 67 | + if v.LexiconNames != nil && len(v.LexiconNames) > 0 { |
| 68 | + objectKey := object.KeyWithValues("LexiconNames") |
| 69 | + for _, name := range v.LexiconNames { |
| 70 | + objectKey.String(name) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + if len(v.OutputFormat) > 0 { |
| 75 | + objectKey := object.Key("OutputFormat") |
| 76 | + objectKey.String(string(v.OutputFormat)) |
| 77 | + } |
| 78 | + |
| 79 | + if v.SampleRate != nil { |
| 80 | + objectKey := object.Key("SampleRate") |
| 81 | + objectKey.String(*v.SampleRate) |
| 82 | + } |
| 83 | + |
| 84 | + if v.Text != nil { |
| 85 | + objectKey := object.Key("Text") |
| 86 | + objectKey.String(*v.Text) |
| 87 | + } |
| 88 | + |
| 89 | + if len(v.TextType) > 0 { |
| 90 | + objectKey := object.Key("TextType") |
| 91 | + objectKey.String(string(v.TextType)) |
| 92 | + } |
| 93 | + |
| 94 | + if len(v.VoiceId) > 0 { |
| 95 | + objectKey := object.Key("VoiceId") |
| 96 | + objectKey.String(string(v.VoiceId)) |
| 97 | + } |
| 98 | + |
| 99 | + return nil |
| 100 | +} |
0 commit comments