forked from protocolbuffers/protobuf-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from infiniteloopcloud/9-go-types-override
Go types override
- Loading branch information
Showing
11 changed files
with
362 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
package internal_gengo | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"testing" | ||
|
||
"github.com/infiniteloopcloud/protoc-gen-go-types/parser" | ||
) | ||
|
||
func TestGenerateFile(t *testing.T) { | ||
gen, err := parser.Parse("./test_data/test.proto") | ||
t.Setenv("TYPE_OVERRIDE", "true") | ||
gen, err := parser.Parse("google/protobuf/descriptor.proto", "./test_data/config.proto", "./test_data/test.proto") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for _, f := range gen.Files { | ||
if f.Generate { | ||
GenerateFile(gen, f) | ||
content, err := GenerateFile(gen, f).Content() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
f, err := os.Create("./test_data/" + f.GeneratedFilenamePrefix + ".pb.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
io.Copy(f, bytes.NewReader(content)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
option go_package = ".;proto"; | ||
|
||
import "google/protobuf/descriptor.proto"; | ||
|
||
extend google.protobuf.FieldOptions { | ||
optional string go_type = 1001; | ||
optional string go_import = 1002; | ||
optional string go_import_alias = 1003; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
option go_package = ".;proto"; | ||
|
||
package proto; | ||
//import "./test_data/config.proto"; | ||
// to test with other languages, switch to this import and run | ||
// cd cmd/protoc-gen-go/internal_gengo | ||
// TYPE_OVERRIDE=true DEBUG=true protoc --go_out=test_data -I test_data test_data/test.proto | ||
import "config.proto"; | ||
|
||
// Or use the following hard coded field option extension | ||
//import "google/protobuf/descriptor.proto"; | ||
// | ||
//extend google.protobuf.FieldOptions { | ||
// optional string go_type = 1001; | ||
// optional string go_import = 1002; | ||
// optional string go_import_alias = 1003; | ||
//} | ||
|
||
message RepeatedString { | ||
} | ||
|
||
message Test { | ||
TimeTime created_at = 1; | ||
map<uint64, RepeatedString> map_field = 2; | ||
int64 created_at = 1 [(go_type) = "time.Time", (go_import) = "time"]; | ||
map<uint64, RepeatedString> map_field = 2 [(go_type) = "map[uint64][]string", (go_import) = ""]; | ||
string test = 3; | ||
String other = 43; | ||
string optStr = 4 [(go_type) = "null.String", (go_import) = "github.com/volatiletech/null/v9", (go_import_alias) = "null"]; | ||
int32 optInt = 5 [(go_type) = "null.Int32"]; | ||
int32 optBigInt = 6 [(go_type) = "null.Int64", (go_import) = "github.com/volatiletech/null/v9", (go_import_alias) = "null"]; | ||
} | ||
|
||
message TimeTime {} | ||
|
||
message RepeatedString {} | ||
|
||
message String { | ||
string string = 2; | ||
} |
Oops, something went wrong.