samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

package name conflict

AndrewWPhillips opened this issue · comments

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
  }