Problems with Text Template

I am building a kind of code generator based in golang templates and I have problems with some characters.

For example if I have got this line in my template
public class {{.Name}}Validator : AbstractValidator<{{.Name}}Input>
is converted to this in my output file
public class GetLoginMarketColorSettingByLoginIDValidator : AbstractValidator&lt; GetLoginMarketColorSettingByLoginIDInput >

Another line when I have got problems :
RuleFor(x => x.{{.Name}}).Cascade(CascadeMode.StopOnFirstFailure){{.ValidationString}};
And ValidationString is build in my code and should be (.NotEmpty().Length(1,15).WithMessage("Not a Valid LoginID");)
But the generated code for this line is
RuleFor(x => x.LoginID).Cascade(CascadeMode.StopOnFirstFailure).NotEmpty().Length(1,15).WithMessage(&#34;Not a Valid LoginID&#34;);

It seems that the template system apply url encoding or it gets confused when a special character is near substitution tag ({{}})

Any hint to solve this problem ?


Hi, Yamil, are you using the text/template package or html/template? I use text/template to generate code just like you are doing and don’t have any problems w/ HTML entity encoding.

yes, you are right!!
When I added the “template.ParseFiles(…)” to my code, my editor automatically loada “html/template” in my imports and I did not check that!!!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.