How transformation handles nested structs
mainTransformation in Fuego is not recursive. If your struct contains nested structs, you must manually call the transformation method of the nested struct within the parent's transformation method. This design provides explicit control and avoids 'magic' behavior.
type Address struct {
Street string `json:"street"`
City string `json:"city"`
}
func (a *Address) InTransform(ctx context.Context) error {
a.Street = strings.TrimSpace(a.Street)
a.City = strings.ToUpper(a.City)
return nil
}
type User struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Address Address `json:"address"`
}
func (u *User) InTransform(ctx context.Context) error {
u.FirstName = strings.ToUpper(u.FirstName)
u.LastName = strings.TrimSpace(u.LastName)
// Manually transform the nested struct
err := u.Address.InTransform(ctx)
if err != nil {
return err
}
return nil
}