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.
add option to set import alias manually
extend the cmd with type and import overrides
- Loading branch information
Showing
5 changed files
with
119 additions
and
29 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
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,11 @@ | ||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
import "google/protobuf/descriptor.proto"; | ||
|
||
extend google.protobuf.FieldOptions { | ||
optional string go_type = 1000; | ||
optional string go_import = 1001; | ||
optional string go_import_alias = 1002; | ||
} |
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,19 @@ | ||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
option go_package = ".;proto"; | ||
|
||
package proto; | ||
import "./test_data/config.proto"; | ||
|
||
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; | ||
} |
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