(x *ast.SelectorExpr, receiverType, fieldName string)
| 415 | } |
| 416 | |
| 417 | func (t *templateData) genSelectorExprGetter(x *ast.SelectorExpr, receiverType, fieldName string) *getter { |
| 418 | if strings.ToLower(fieldName[:1]) == fieldName[:1] { // Non-exported field. |
| 419 | return nil |
| 420 | } |
| 421 | |
| 422 | var xX string |
| 423 | if xx, ok := x.X.(*ast.Ident); ok { |
| 424 | xX = xx.String() |
| 425 | } |
| 426 | |
| 427 | switch xX { |
| 428 | case "time", "json": |
| 429 | if xX == "json" { |
| 430 | t.Imports["encoding/json"] = "encoding/json" |
| 431 | } else { |
| 432 | t.Imports[xX] = xX |
| 433 | } |
| 434 | fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name) |
| 435 | zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name) |
| 436 | if xX == "time" && x.Sel.Name == "Duration" { |
| 437 | zeroValue = "0" |
| 438 | } |
| 439 | return newGetter(receiverType, fieldName, fieldType, zeroValue, false) |
| 440 | default: |
| 441 | logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x) |
| 442 | } |
| 443 | |
| 444 | return nil |
| 445 | } |
| 446 | |
| 447 | type templateData struct { |
| 448 | filename string |
no test coverage detected