-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: I need this functionality extracted. It will be invoked downstream by the reflection decoder to apply defaults to a blank struct. Reviewed By: leoleovich Differential Revision: D63505752 fbshipit-source-id: 6371e0d295facc44f21a8372aa5a42a9a6d0f58f
- Loading branch information
1 parent
883b971
commit 574f160
Showing
98 changed files
with
5,695 additions
and
2,307 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
53 changes: 53 additions & 0 deletions
53
thrift/compiler/generate/templates/go/types/struct_method_set_defaults.mustache
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,53 @@ | ||
{{! | ||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
Licensed 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. | ||
}}{{! | ||
This template creates a setDefaults method for Thrift structs. | ||
}} | ||
func (x *{{struct:go_name}}) setDefaults() *{{struct:go_name}} { | ||
return x{{! | ||
}}{{^struct:union?}}{{! | ||
}}{{#struct:fields_sorted}}{{! | ||
// Fields with given default values. | ||
}}{{#field:value}}. | ||
{{field:go_setter_name}}{{#program:compat_setters?}}NonCompat{{/program:compat_setters?}}({{! | ||
}}{{#field:type}}{{! | ||
}}{{^type:base?}} | ||
{{> const/value}}, | ||
{{/type:base?}}{{! | ||
}}{{#type:base?}}{{! | ||
}}{{> const/value}}{{! | ||
}}{{/type:base?}}{{! | ||
}}{{/field:type}}{{! | ||
}}){{/field:value}}{{! | ||
// Non-optional fields without given default values. | ||
}}{{^field:value}}{{! | ||
}}{{^field:optional?}}. | ||
{{field:go_setter_name}}{{#program:compat_setters?}}NonCompat{{/program:compat_setters?}}({{! | ||
}}{{#field:type}}{{! | ||
}}{{> common/natural_default_value}}{{! | ||
}}{{/field:type}}{{! | ||
}}){{/field:optional?}}{{! | ||
}}{{/field:value}}{{! | ||
}}{{/struct:fields_sorted}}{{! | ||
}}{{/struct:union?}} | ||
} | ||
{{!newline}} |
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
Oops, something went wrong.