samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for `package_prefix` in generator

lithammer opened this issue · comments

The official Thrift compiler has a Go specific flag called package_prefix:

$ thrift --help
  go (Go):
    package_prefix= Package prefix for generated files.
    thrift_import=  Override thrift package import path (default:git.apache.org/thrift.git/lib/go/thrift)
    package=  Package name (default: inferred from thrift file name)

My problem is this. So I have two spec files:

foo.thrift

include "common.thrift"

struct Foo {
    1: string name
}

common.thrift

exception InternalServiceError {
    1: string message
}

So when I generate this using $ generator foo.thrift rpc my foo.go will contain a broken/bad import path..

// This file is automatically generated. Do not modify.

package foo

import (
    "common"    // <---- Bad import!
    "fmt"
)

var _ = fmt.Printf

type Foo struct {
    Name string `thrift:"1,required" json:"name"`
}

This import should ideally be something illustrated by this diff:

 import (
-    "common"
+    "github.com/renstrom/my_project/rpc/common"
     "fmt"
 )

Are am I using this all wrong?

Fixed by #55