Esempio n. 1
0
// GoCode returns the rendered Go code for the Shape.
func (s *Shape) GoCode() string {
	code := s.Docstring()
	if !s.IsEnum() {
		code += "type " + s.ShapeName + " "
	}

	switch {
	case s.Type == "structure":
		ref := &ShapeRef{ShapeName: s.ShapeName, API: s.API, Shape: s}

		code += "struct {\n"
		code += "_ struct{} " + ref.GoTags(true, false) + "\n\n"
		for _, n := range s.MemberNames() {
			m := s.MemberRefs[n]
			code += m.Docstring()
			if (m.Streaming || m.Shape.Streaming) && s.Payload == n {
				rtype := "io.ReadSeeker"
				if len(s.refs) > 1 {
					rtype = "aws.ReaderSeekCloser"
				} else if strings.HasSuffix(s.ShapeName, "Output") {
					rtype = "io.ReadCloser"
				}

				s.API.imports["io"] = true
				code += n + " " + rtype + " " + m.GoTags(false, s.IsRequired(n)) + "\n\n"
			} else {
				code += n + " " + m.GoType() + " " + m.GoTags(false, s.IsRequired(n)) + "\n\n"
			}
		}
		code += "}"

		if !s.API.NoStringerMethods {
			code += s.goCodeStringers()
		}
	case s.IsEnum():
		code += "const (\n"
		for n, e := range s.Enum {
			code += fmt.Sprintf("\t// @enum %s\n\t%s = %q\n",
				s.ShapeName, s.EnumConsts[n], e)
		}
		code += ")"
	default:
		panic("Cannot generate toplevel shape for " + s.Type)
	}

	return util.GoFmt(code)
}
Esempio n. 2
0
func main() {
	out := generateTestSuite(os.Args[1])
	if len(os.Args) == 3 {
		f, err := os.Create(os.Args[2])
		defer f.Close()
		if err != nil {
			panic(err)
		}
		f.WriteString(util.GoFmt(out))
		f.Close()

		c := exec.Command("gofmt", "-s", "-w", os.Args[2])
		if err := c.Run(); err != nil {
			panic(err)
		}
	} else {
		fmt.Println(out)
	}
}
Esempio n. 3
0
// ParamsStructFromJSON returns a JSON string representation of a structure.
func ParamsStructFromJSON(value interface{}, shape *api.Shape, prefixPackageName bool) string {
	f := paramFiller{prefixPackageName: prefixPackageName}
	return util.GoFmt(f.paramsStructAny(value, shape))
}
Esempio n. 4
0
func writeGoFile(file string, layout string, args ...interface{}) error {
	return ioutil.WriteFile(file, []byte(util.GoFmt(fmt.Sprintf(layout, args...))), 0664)
}