@@ -299,6 +299,13 @@ class t_mstch_go_generator : public t_mstch_generator {
299299 self.find_structured_annotation_or_null (kGoUseReflectCodecUri );
300300 return data_.use_reflect_codec || use_reflect_codec_annotation != nullptr ;
301301 });
302+ def.property (" go_qualified_new_func" , [this ](const t_structured& self) {
303+ return fmt::format (
304+ " {}{}{}" ,
305+ data_.go_package_alias_prefix (self.program ()),
306+ data_.is_req_resp_struct (self) ? " new" : " New" ,
307+ go::munge_ident (self.name (), /* exported=*/ true ));
308+ });
302309
303310 return std::move (def).make ();
304311 }
@@ -530,8 +537,6 @@ class mstch_go_struct : public mstch_struct {
530537 {
531538 {" struct:go_name" , &mstch_go_struct::go_name},
532539 {" struct:go_qualified_name" , &mstch_go_struct::go_qualified_name},
533- {" struct:go_qualified_new_func" ,
534- &mstch_go_struct::go_qualified_new_func},
535540 {" struct:req_resp?" , &mstch_go_struct::is_req_resp_struct},
536541 {" struct:resp?" , &mstch_go_struct::is_resp_struct},
537542 {" struct:req?" , &mstch_go_struct::is_req_struct},
@@ -545,27 +550,23 @@ class mstch_go_struct : public mstch_struct {
545550 auto prefix = data_.go_package_alias_prefix (struct_->program ());
546551 return prefix + go_name_ ();
547552 }
548- mstch::node go_qualified_new_func () {
549- auto prefix = data_.go_package_alias_prefix (struct_->program ());
550- return prefix + go_new_func_ ();
551- }
552553 mstch::node is_req_resp_struct () {
553554 // Whether this is a helper request or response struct.
554- return is_req_resp_struct_ ( );
555+ return data_. is_req_resp_struct (*struct_ );
555556 }
556557 mstch::node is_resp_struct () {
557558 // Whether this is a helper response struct.
558- return is_req_resp_struct_ ( ) &&
559+ return data_. is_req_resp_struct (*struct_ ) &&
559560 boost::algorithm::starts_with (struct_->name (), " resp" );
560561 }
561562 mstch::node is_req_struct () {
562563 // Whether this is a helper request struct.
563- return is_req_resp_struct_ ( ) &&
564+ return data_. is_req_resp_struct (*struct_ ) &&
564565 boost::algorithm::starts_with (struct_->name (), " req" );
565566 }
566567 mstch::node is_stream_struct () {
567568 // Whether this is a helper stream struct.
568- return is_req_resp_struct_ ( ) &&
569+ return data_. is_req_resp_struct (*struct_ ) &&
569570 boost::algorithm::starts_with (struct_->name (), " stream" );
570571 }
571572 mstch::node fields_sorted () {
@@ -585,7 +586,7 @@ class mstch_go_struct : public mstch_struct {
585586
586587 std::string go_name_ () {
587588 auto name = struct_->name ();
588- if (is_req_resp_struct_ ( )) {
589+ if (data_. is_req_resp_struct (*struct_ )) {
589590 // Unexported/lowercase
590591 return go::munge_ident (name, false );
591592 } else {
@@ -597,26 +598,6 @@ class mstch_go_struct : public mstch_struct {
597598 return go::munge_ident (name, true );
598599 }
599600 }
600-
601- std::string go_new_func_ () {
602- auto name = struct_->name ();
603- auto go_name = go::munge_ident (struct_->name (), true );
604- if (is_req_resp_struct_ ()) {
605- // Unexported/lowercase
606- return " new" + go_name;
607- } else {
608- // Exported/uppercase
609- return " New" + go_name;
610- }
611- }
612-
613- bool is_req_resp_struct_ () {
614- return struct_->generated () &&
615- std::find (
616- data_.req_resp_structs .begin (),
617- data_.req_resp_structs .end (),
618- struct_) != data_.req_resp_structs .end ();
619- }
620601};
621602
622603void t_mstch_go_generator::generate_program () {
0 commit comments