-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-3037 Go Codegen - Support Struct TypeDefs #2888
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,8 @@ class t_go_generator : public t_generator { | |
bool is_args = false); | ||
void generate_go_struct_initializer(std::ostream& out, | ||
t_struct* tstruct, | ||
bool is_args_or_result = false); | ||
bool is_args_or_result = false, | ||
string alias_name = ""); | ||
void generate_isset_helpers(std::ostream& out, | ||
t_struct* tstruct, | ||
const string& tstruct_name, | ||
|
@@ -176,7 +177,8 @@ class t_go_generator : public t_generator { | |
t_struct* tstruct, | ||
bool is_pointer_field, | ||
bool declare, | ||
std::string prefix = ""); | ||
std::string prefix = "", | ||
string alias_name = ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use it doesn't look like we are very consistent here, but being consistent partially is still better, while the line right above is using |
||
|
||
void generate_deserialize_container(std::ostream& out, | ||
t_type* ttype, | ||
|
@@ -264,7 +266,7 @@ class t_go_generator : public t_generator { | |
std::string argument_list(t_struct* tstruct); | ||
std::string type_to_enum(t_type* ttype); | ||
std::string type_to_go_type(t_type* ttype); | ||
std::string type_to_go_type_with_opt(t_type* ttype, bool optional_field); | ||
std::string type_to_go_type_with_opt(t_type* ttype, bool optional_field = false, bool no_struct_ptr = false); | ||
std::string type_to_go_key_type(t_type* ttype); | ||
std::string type_to_spec_args(t_type* ttype); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,8 @@ gopath: $(THRIFT) $(THRIFTTEST) \ | |
ProcessorMiddlewareTest.thrift \ | ||
ClientMiddlewareExceptionTest.thrift \ | ||
ValidateTest.thrift \ | ||
ForwardType.thrift | ||
ForwardType.thrift \ | ||
TypedefServiceTest.thrift | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
mkdir -p gopath/src | ||
grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set<Insanity>' > ThriftTest.thrift | ||
$(THRIFT) $(THRIFTARGS) -r IncludesTest.thrift | ||
|
@@ -98,6 +99,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \ | |
$(THRIFT) $(THRIFTARGS) ClientMiddlewareExceptionTest.thrift | ||
$(THRIFT) $(THRIFTARGS) ValidateTest.thrift | ||
$(THRIFT) $(THRIFTARGS) ForwardType.thrift | ||
$(THRIFT) $(THRIFTARGS) TypedefServiceTest.thrift | ||
ln -nfs ../../tests gopath/src/tests | ||
cp -r ./dontexportrwtest gopath/src | ||
touch gopath | ||
|
@@ -124,7 +126,8 @@ check: gopath | |
./gopath/src/processormiddlewaretest \ | ||
./gopath/src/clientmiddlewareexceptiontest \ | ||
./gopath/src/validatetest \ | ||
./gopath/src/forwardtypetest | ||
./gopath/src/forwardtypetest \ | ||
./gopath/src/typedefservicetest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong indentation (should be 4 |
||
$(GO) test github.com/apache/thrift/lib/go/thrift | ||
$(GO) test ./gopath/src/tests ./gopath/src/dontexportrwtest | ||
|
||
|
@@ -172,4 +175,5 @@ EXTRA_DIST = \ | |
TypedefFieldTest.thrift \ | ||
UnionBinaryTest.thrift \ | ||
UnionDefaultValueTest.thrift \ | ||
ValidateTest.thrift | ||
ValidateTest.thrift \ | ||
TypedefServiceTest.thrift | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong indentation (should be a tab instead of 4 spaces) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
# We are only testing that generated code compiles, no correctness checking is done | ||
|
||
struct ExampleRequest { | ||
1: required string example_field | ||
} | ||
|
||
struct ExampleResponse { | ||
1: required string example_field | ||
} | ||
|
||
struct ExampleOptionalRequest { | ||
1: optional string example_field | ||
} | ||
|
||
struct ExampleOptionalResponse { | ||
1: optional string example_field | ||
} | ||
|
||
struct ExampleNested { | ||
1: required string example_field | ||
} | ||
|
||
struct ExampleOptionalNestedRequest { | ||
1: optional ExampleNested example_field | ||
} | ||
|
||
struct ExampleOptionalNestedResponse { | ||
1: optional ExampleNested example_field | ||
} | ||
|
||
typedef ExampleRequest TypedefExampleRequest | ||
typedef ExampleResponse TypedefExampleResponse | ||
|
||
typedef string PrimativeTypedefExampleRequest | ||
typedef string PrimativeTypedefExampleResponse | ||
|
||
service TypeDefService { | ||
ExampleResponse exampleMethod(1: ExampleRequest request) | ||
TypedefExampleResponse typedefExampleMethod(1: TypedefExampleRequest request) | ||
string primativeExampleMethod(1: string request) | ||
PrimativeTypedefExampleResponse primativeTypedefExampleMethod(1: PrimativeTypedefExampleRequest request) | ||
ExampleOptionalResponse exampleOptionalMethod(1: ExampleOptionalRequest request) | ||
ExampleOptionalNestedResponse exampleOptionalNestedMethod(1: ExampleOptionalNestedRequest request) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/thrift/lib/go/test/gopath/src/typedefservicetest" | ||
) | ||
|
||
func TestTypedefService(t *testing.T) { | ||
// We need to import the generated code to ensure it compiles | ||
_ = &typedefservicetest.TypedefExampleRequest{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar here, let's use
std::string
instead