コード例 #1
0
ファイル: types.go プロジェクト: cw2018/goa
// GoTypeRef returns the Go code that refers to the Go type which matches the given data type
// (the part that comes after `var foo`)
// tabs is used to properly tabulate the object struct fields and only applies to this case.
func GoTypeRef(t design.DataType, tabs int) string {
	switch t.(type) {
	case *design.UserTypeDefinition, *design.MediaTypeDefinition:
		var prefix string
		if t.IsObject() {
			prefix = "*"
		}
		return prefix + GoTypeName(t, tabs)
	case design.Object:
		return "*" + GoTypeName(t, tabs)
	default:
		return GoTypeName(t, tabs)
	}
}
コード例 #2
0
ファイル: types.go プロジェクト: yonglehou/goa
// GoPackageTypeRef returns the Go code that refers to the Go type which matches the given data type.
// versioned indicates whether the type is being referenced from a version package (true) or the
// default package defPkg (false).
// required only applies when referring to a user type that is an object defined inline. In this
// case the type (Object) does not carry the required field information defined in the parent
// (anonymous) attribute.
// tabs is used to properly tabulate the object struct fields and only applies to this case.
func GoPackageTypeRef(t design.DataType, required []string, versioned bool, defPkg string, tabs int) string {
	switch t.(type) {
	case *design.UserTypeDefinition, *design.MediaTypeDefinition:
		var prefix string
		if t.IsObject() {
			prefix = "*"
		}
		return prefix + GoPackageTypeName(t, required, versioned, defPkg, tabs)
	case design.Object:
		return "*" + GoPackageTypeName(t, required, versioned, defPkg, tabs)
	default:
		return GoPackageTypeName(t, required, versioned, defPkg, tabs)
	}
}