github.com/aavshr/aws-sdk-go@v1.41.3/private/model/api/examples_builder.go (about)

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