Ejemplo n.º 1
0
// qualifiedTypeName returns the qualified type name for the given data type.
// This is useful in reporting types in error messages.
// (e.g) array<string>, hash<string, string>, hash<string, array<int>>
func qualifiedTypeName(t design.DataType) string {
	switch t.Kind() {
	case design.DateTimeKind:
		return "datetime"
	case design.ArrayKind:
		return fmt.Sprintf("%s<%s>", t.Name(), qualifiedTypeName(t.ToArray().ElemType.Type))
	case design.HashKind:
		h := t.ToHash()
		return fmt.Sprintf("%s<%s, %s>",
			t.Name(),
			qualifiedTypeName(h.KeyType.Type),
			qualifiedTypeName(h.ElemType.Type),
		)
	}
	return t.Name()
}
Ejemplo n.º 2
0
// cmdFieldTypeString computes the Go type name used to store command flags of the given design type. Complex types are String
func cmdFieldTypeString(t design.DataType, point bool) string {
	var pointer, suffix string
	if point && !t.IsArray() {
		pointer = "*"
	}
	if t.Kind() == design.UUIDKind || t.Kind() == design.DateTimeKind || t.Kind() == design.AnyKind || t.Kind() == design.NumberKind || t.Kind() == design.BooleanKind {
		suffix = "string"
	} else if isArrayOfType(t, design.UUIDKind, design.DateTimeKind, design.AnyKind, design.NumberKind, design.BooleanKind) {
		suffix = "[]string"
	} else {
		suffix = codegen.GoNativeType(t)
	}
	return pointer + suffix
}
Ejemplo n.º 3
0
// cmdFieldType computes the Go type name used to store command flags of the given design type.
func cmdFieldType(t design.DataType) string {
	if t.Kind() == design.DateTimeKind || t.Kind() == design.UUIDKind {
		return "string"
	}
	return codegen.GoNativeType(t)
}