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
feat(method): support method in definition #211
Conversation
@kdada few comments:
It's common to register multiple methods of a class, in current setup, users are supposed to do this multiple times, each time with a new instance of the object?
|
👆 @kdada can u provide some pprof results (esp. memory for objects)? that will make me feel better ... |
The
Benchmark:
Function warp has twice consumption than direct call. But it isn't a big deal. Because the overhead of an entire API request is in microsecond. (PS. I'll write an unsafe calling package to skip the safe check of reflect packge. ) |
func (t *TestStruct) Number() int { | ||
return t.a | ||
} | ||
|
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.
add another struct implement TestInterface,used for test putInterface.
func (t *Test2Struct) Number() int {
return t.a*2
}
definition/method/method_test.go
Outdated
func TestContainer(t *testing.T) { | ||
cases := []struct { | ||
typ interface{} | ||
instance interface{} |
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.
func NewTest(number int) TestInterface{
return &TestStruct{
a: number,
}
}
Usually the initialization instance is a factory, and the instance can use the following method?
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kdada, zjj2wry The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
In the past,
definition.Function
only support functions. Withmethod
package in this pr, you can get the power to make a method be like a function.Then you don't need to do this:
Which issue(s) this PR is related to (optional, link to 3rd issue(s)):
Fixes #
Reference to #
Special notes for your reviewer:
/cc @ddysher
Release note: