Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4253

Go generator assigns strings to field in const instead of pointers.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.12.0
    • Go - Compiler
    • None
    • Generated using docker-thrift.

    Description

      Given the follow thrift definition:

      struct custom {
        1: required string field_a;
        2: optional string field_b;
      }
      

      with the following constant map defined in the same file:

      const map<i32, custom> custom_map = {
        ...,
        42 : { 'field_a':'www.testa.com', 'field_b':'www.testb.com'},
        ...,
      }
      

      Thrift generates the following go struct in the main

      x.go

      file:

      type Custom struct {
        FieldA string `thrift:"field_a,required" db:"field_a" json:"field_a"`
        FieldB *string `thrift:"field_b,2" db:"field_b" json:"field_b,omitempty"`
      }
      

      with the corresponding assignments in the

       X-consts.go 

      file:

      CUSTOM_MAP = map[int]*Custom {
        ...,
        42: &Custom {FieldA: "www.testa.com", FieldB: "www.testb.com"},
        ...,
      }
      

      I assume field_b's pointer type is to allow for null values as per the optional. The generator should be assigning pointers instead of strings.

      I'm not sure how much effort it would take to fix this. I am encountering this problem at work right and would be very happy to starting working on this with some guidance from experts around here.

      Attachments

        Issue Links

          Activity

            People

              jking3 James E. King III
              DavinC Davin Chia
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: