@@ -199,6 +199,45 @@ def message_has_unions(self, message: Message) -> bool:
199199 PrimitiveKind .ANY : "any" ,
200200 }
201201
202+ def wrap_line (
203+ self ,
204+ line : str ,
205+ max_width : int = 80 ,
206+ indent : str = "" ,
207+ continuation_indent : str = None ,
208+ ) -> List [str ]:
209+ """Override base wrap_line to handle Go-specific syntax.
210+
211+ Go has specific constructs that should not be wrapped:
212+ 1. Function signatures - must not split between params and return type
213+ 2. Struct field tags - backtick strings must not be split
214+ 3. Single-line function bodies - must not split "{ return ... }"
215+ """
216+ if continuation_indent is None :
217+ continuation_indent = indent + " "
218+
219+ # If line is already short enough, return as is
220+ if len (line ) <= max_width :
221+ return [line ]
222+
223+ stripped = line .lstrip ()
224+
225+ # Don't wrap comments
226+ if stripped .startswith ("//" ) or stripped .startswith ("/*" ) or stripped .startswith ("*" ):
227+ return [line ]
228+
229+ # Don't wrap lines with backticks (struct tags)
230+ if "`" in line :
231+ return [line ]
232+
233+ # Don't wrap function definitions (including one-liners like "func Foo() Type { return ... }")
234+ # Detect by checking if line starts with "func " and contains "{"
235+ if stripped .startswith ("func " ) and "{" in line :
236+ return [line ]
237+
238+ # For all other cases, use base class wrapping
239+ return super ().wrap_line (line , max_width , indent , continuation_indent )
240+
202241 def generate (self ) -> List [GeneratedFile ]:
203242 """Generate Go files for the schema."""
204243 files = []
@@ -586,15 +625,13 @@ def generate_union(
586625 lines .append (f"\t case { case_type } { case_name } :" )
587626 lines .append (f"\t \t v, ok := u.value.({ case_type_name } )" )
588627 lines .append ("\t \t if !ok {" )
589- lines .append (
590- f'\t \t \t return fmt.Errorf("corrupted { type_name } : case={ case_name } but invalid value")'
591- )
628+ lines .append (f'\t \t \t return fmt.Errorf("corrupted { type_name } : " +' )
629+ lines .append (f'\t \t \t \t "case={ case_name } but invalid value")' )
592630 lines .append ("\t \t }" )
593631 if case_type_name .startswith ("*" ):
594632 lines .append ("\t \t if v == nil {" )
595- lines .append (
596- f'\t \t \t return fmt.Errorf("corrupted { type_name } : case={ case_name } but nil value")'
597- )
633+ lines .append (f'\t \t \t return fmt.Errorf("corrupted { type_name } : " +' )
634+ lines .append (f'\t \t \t \t "case={ case_name } but nil value")' )
598635 lines .append ("\t \t }" )
599636 lines .append (f"\t \t if visitor.{ case_name } != nil {{" )
600637 lines .append (f"\t \t \t return visitor.{ case_name } (v)" )
@@ -864,7 +901,8 @@ def generate_field(
864901
865902 if tags :
866903 tag_str = "," .join (tags )
867- lines .append (f'{ field_name } { go_type } `fory:"{ tag_str } "`' )
904+ # Concatenate parts to ensure single line in output
905+ lines .append (f"{ field_name } { go_type } `fory:\" { tag_str } \" `" )
868906 else :
869907 lines .append (f"{ field_name } { go_type } " )
870908
0 commit comments