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