cmd/tools/gen-accessors.go
func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) {
	if strings.ToLower(fieldName[:1]) == fieldName[:1] { // non-exported field
		return
	}

	var xX string
	if xx, ok := x.X.(*ast.Ident); ok {
		xX = xx.String()
	}

	switch xX {
	case "time", "json":
		if xX == "json" {
			t.Imports["encoding/json"] = "encoding/json"
		} else {
			t.Imports[xX] = xX
		}
		fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name)
		zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name)
		if xX == "json" && x.Sel.Name == "Number" {
			zeroValue = `""`
		}
		if xX == "time" && x.Sel.Name == "Duration" {
			zeroValue = "0"
		}
		t.Accessors = append(t.Accessors, newAccessor(receiverType, fieldName, fieldType, zeroValue))
	default:
		logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x)
	}
}
func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) {
	if strings.ToLower(fieldName[:1]) == fieldName[:1] { // non-exported field
		return
	}

	var xX string
	if xx, ok := x.X.(*ast.Ident); ok {
		xX = xx.String()
	}

	switch xX {
	case "time", "json":
		if xX == "json" {
			t.Imports["encoding/json"] = "encoding/json"
		} else {
			t.Imports[xX] = xX
		}
		fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name)
		zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name)
		if xX == "json" && x.Sel.Name == "Number" {
			zeroValue = `""`
		}
		if xX == "time" && x.Sel.Name == "Duration" {
			zeroValue = "0"
		}
		t.Accessors = append(t.Accessors, newAccessor(receiverType, fieldName, fieldType, zeroValue))
	default:
		logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x)
	}
}
func ( t * templateData ) addSelectorExpr ( x * ast . SelectorExpr , receiverType , fieldName string ) { if strings . ToLower ( fieldName [ : 1 ] ) == fieldName [ : 1 ] { // non-exported field return } var xX string if xx , ok := x . X . ( * ast . Ident ) ; ok { xX = xx . String ( ) } switch xX { case " " , " " : if xX == " " { t . Imports [ " " ] = " " } else { t . Imports [ xX ] = xX } fieldType := fmt . Sprintf ( " " , xX , x . Sel . Name ) zeroValue := fmt . Sprintf ( " " , xX , x . Sel . Name ) if xX == " " && x . Sel . Name == " " { zeroValue = `""` } if xX == " " && x . Sel . Name == " " { zeroValue = " " } t . Accessors = append ( t . Accessors , newAccessor ( receiverType , fieldName , fieldType , zeroValue ) ) default : logf ( " " , xX , receiverType , fieldName , x ) } }
// addSelectorExpr adds an accessor for an identifier selector expression, for a given receiver and field
addSelectorExpr adds an accessor for an identifier selector expression for a given receiver and field