GoTypeDef returns the Go code that defines a Go type which matches the data structure definition (the part that comes after `type foo`). ptr if true indicates that the attribute must be stored in a pointer (except array and map types which are always non-pointers) useDefault if true indicates that
(att *expr.AttributeExpr, ptr, useDefault bool)
| 123 | // useDefault if true indicates that the attribute must not be a pointer |
| 124 | // if it has a default value. |
| 125 | func (s *NameScope) GoTypeDef(att *expr.AttributeExpr, ptr, useDefault bool) string { |
| 126 | pkg := "" |
| 127 | if loc := UserTypeLocation(att.Type); loc != nil { |
| 128 | pkg = loc.PackageName() |
| 129 | } else if p, ok := att.Meta.Last("struct:pkg:path"); ok && p != "" { |
| 130 | pkg = Goify(filepath.Base(p), false) |
| 131 | } |
| 132 | return s.goTypeDef(att, ptr, useDefault, pkg) |
| 133 | } |
| 134 | |
| 135 | // GoTypeDefWithTargetPkg returns the Go type definition string, qualifying any |
| 136 | // user types inside inline structs with the provided target package. This helps |