From 17d8186616ece55c955fb74eddb5645c4e1c8621 Mon Sep 17 00:00:00 2001 From: Sergey Polygalin Date: Thu, 23 Nov 2023 13:46:51 +0300 Subject: [PATCH] Default value for virtual with default null --- tpl/macros_struct.twig | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index 5b928c4..3c931a6 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -479,10 +479,18 @@ func (s *{{ name|default(o.name) }}) Reset() { s.{{ fname }} = s.{{ fname }}[:0] } {% elseif f.type is struct %} - {% if has_token(f, 'virtual') %} - s.{{ fname }} = New{{ f.type|go_type }}() + {% if token(f, 'default', '') != 'null' %} + {% if has_token(f, 'virtual') %} + s.{{ fname }} = New{{ f.type|go_type }}() + {% else %} + s.{{ fname }}.Reset() + {% endif %} {% else %} - s.{{ fname }}.Reset() + {% if has_token(f, 'virtual') %} + s.{{ fname }} = &{{ f.type|go_type }}{} + {% else %} + s.{{ fname }}.Reset() + {% endif %} {% endif %} {% else %} s.{{ fname }} = {{ f|default_val }}