1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
//go:build codegen
// +build codegen
package api
import (
"fmt"
"github.com/aws/aws-sdk-go/private/protocol"
)
type examplesBuilder interface {
BuildShape(*ShapeRef, map[string]interface{}, bool) string
BuildList(string, string, *ShapeRef, []interface{}) string
BuildComplex(string, string, *ShapeRef, *Shape, map[string]interface{}) string
GoType(*ShapeRef, bool) string
Imports(*API) string
}
type defaultExamplesBuilder struct {
ShapeValueBuilder
}
// NewExamplesBuilder returns an initialized example builder for generating
// example input API shapes from a model.
func NewExamplesBuilder() defaultExamplesBuilder {
b := defaultExamplesBuilder{
ShapeValueBuilder: NewShapeValueBuilder(),
}
b.ParseTimeString = parseExampleTimeString
return b
}
func (builder defaultExamplesBuilder) Imports(a *API) string {
return `"fmt"
"strings"
"time"
"` + SDKImportRoot + `/aws"
"` + SDKImportRoot + `/aws/awserr"
"` + SDKImportRoot + `/aws/session"
"` + a.ImportPath() + `"
`
}
// Returns a string which assigns the value of a time member by calling
// parseTime function defined in the file
func parseExampleTimeString(ref *ShapeRef, memName, v string) string {
if ref.Location == "header" {
return fmt.Sprintf("%s: parseTime(%q, %q),\n", memName, protocol.RFC822TimeFormat, v)
}
switch ref.API.Metadata.Protocol {
case "json", "rest-json", "rest-xml", "ec2", "query":
return fmt.Sprintf("%s: parseTime(%q, %q),\n", memName, protocol.ISO8601TimeFormat, v)
default:
panic("Unsupported time type: " + ref.API.Metadata.Protocol)
}
}
|