samuel / go-thrift

A native Thrift package for Go
BSD 3-Clause "New" or "Revised" License
384 stars 110 forks source link

package name conflict #99

Open AndrewWPhillips opened 7 years ago

AndrewWPhillips commented 7 years ago

Go packages can't be nested but you can nest namespaces in Thrift. If you have two Thrift files with the same "leaf" namespace name then when both namespaces are used together the generated Go code won't compile. The error is redeclared as imported package name ...

Eg for this thrift:

  include "Person.Address.thrift"
  include "Computer.Address.thrift"

  struct Details
  {
    1 : optional Person.Address.Primary addr,
    2 : optional Computer.Address.Primary ip,
  }

the Go code looks something like this:

  import (
    "Person/Address"
    "Computer/Address"     // Address redeclared as imported package name
    "git.apache.org/thrift.git/lib/go/thrift"
  )
  .....
  type Details struct {
    Addr             *Address.Primary
    Ip               *Address.Primary
  }

This is not a big problem but could be avoided by importing the package under a non-conflicting name like this:

  import (
    PersonAddress   "Person/Address"
    ComputerAddress "Computer/Address"
    "git.apache.org/thrift.git/lib/go/thrift"
  )
  .....
  type Details struct {
    Addr             *PersonAddress.Primary
    Ip               *ComputerAddress.Primary
  }