forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 62
request: switch all request types to value receivers and value returns #584
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
Open
bigbes
wants to merge
1
commit into
master
Choose a base branch
from
bigbes/gh-238-request-value-receivers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -182,6 +182,51 @@ TODO | |||||
| stream, _ := conn.NewStream() | ||||||
| log.Printf("opened stream on %v", conn) | ||||||
| ``` | ||||||
| * All request types (`PingRequest`, `SelectRequest`, `CallRequest`, etc.) now | ||||||
| use value receivers and constructors return values instead of pointers. | ||||||
| Builder methods return modified copies instead of mutating in place. | ||||||
|
|
||||||
| **Breaking**: calling a builder method without using its return value silently | ||||||
| discards the change: | ||||||
| ```Go | ||||||
| // Before (pointer receivers, mutation in place): | ||||||
| req := NewSelectRequest("space") | ||||||
| req.Index("idx") // mutated req directly | ||||||
| conn.Do(req) | ||||||
|
|
||||||
| // After (value receivers, must use return value): | ||||||
| req := NewSelectRequest("space") | ||||||
| req = req.Index("idx") // must reassign | ||||||
|
Collaborator
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. etc
Suggested change
|
||||||
| conn.Do(req) | ||||||
|
|
||||||
| // Or chain directly: | ||||||
| conn.Do(NewSelectRequest("space").Index("idx")) | ||||||
| ``` | ||||||
|
|
||||||
| The same value-receiver pattern was applied to `arrow.InsertRequest` and | ||||||
| `settings.SetRequest`/`settings.GetRequest`. | ||||||
|
|
||||||
| In the `box` subpackage, request types (`InfoRequest`, `UserExistsRequest`, | ||||||
| `UserCreateRequest`, `SessionSuRequest`, etc.) no longer embed | ||||||
| `tarantool.CallRequest`. They store it as a private field and implement | ||||||
| their own `Context()` method returning the wrapper type. Usage stays clean: | ||||||
| ```Go | ||||||
| req := box.NewUserExistsRequest(username).Context(ctx) | ||||||
| ``` | ||||||
| * Renamed value constructors from `Make*` to `New*` for naming consistency | ||||||
| across the connector. Previously, the main package used `New*Request` while | ||||||
| the `crud` package and value-type constructors used `Make*`. They now all | ||||||
| use the `New*` prefix. | ||||||
|
|
||||||
| | Before | After | | ||||||
| |---|---| | ||||||
| | `datetime.MakeDatetime` | `datetime.NewDatetime` | | ||||||
| | `decimal.MakeDecimal` | `decimal.NewDecimal` | | ||||||
| | `decimal.MakeDecimalFromString` | `decimal.NewDecimalFromString` | | ||||||
| | `decimal.MustMakeDecimal` | `decimal.MustNewDecimal` | | ||||||
| | `arrow.MakeArrow` | `arrow.NewArrow` | | ||||||
| | `crud.MakeResult` | `crud.NewResult` | | ||||||
| | `crud.Make*Request` (all of them) | `crud.New*Request` | | ||||||
|
|
||||||
| ## Migration from v1.x.x to v2.x.x | ||||||
|
|
||||||
|
|
@@ -440,12 +485,13 @@ is supported. | |||||
|
|
||||||
| Now you need to use objects of the Datetime type instead of pointers to it. A | ||||||
| new constructor `MakeDatetime` returns an object. `NewDatetime` has been | ||||||
| removed. | ||||||
| removed. (`MakeDatetime` was later renamed back to `NewDatetime` in v3.) | ||||||
|
|
||||||
| ### decimal package | ||||||
|
|
||||||
| Now you need to use objects of the Decimal type instead of pointers to it. A | ||||||
| new constructor `MakeDecimal` returns an object. `NewDecimal` has been removed. | ||||||
| (`MakeDecimal` was later renamed back to `NewDecimal` in v3.) | ||||||
|
|
||||||
| ### multi package | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| package box | ||
|
|
||
| import ( | ||
| "context" | ||
| "io" | ||
|
|
||
| "github.com/tarantool/go-iproto" | ||
| "github.com/vmihailenco/msgpack/v5" | ||
|
|
||
| "github.com/tarantool/go-tarantool/v3" | ||
| ) | ||
|
|
||
| // baseCallRequest wraps a tarantool.CallRequest and implements | ||
| // the tarantool.Request interface by delegation. | ||
| type baseCallRequest struct { | ||
| call tarantool.CallRequest | ||
| } | ||
|
|
||
| // Type returns IPROTO type for the request. | ||
| func (req baseCallRequest) Type() iproto.Type { | ||
| return req.call.Type() | ||
| } | ||
|
|
||
| // Body fills an encoder with the request body. | ||
| func (req baseCallRequest) Body(res tarantool.SchemaResolver, | ||
| enc *msgpack.Encoder) error { | ||
| return req.call.Body(res, enc) | ||
| } | ||
|
|
||
| // Ctx returns a context of the request. | ||
| func (req baseCallRequest) Ctx() context.Context { | ||
| return req.call.Ctx() | ||
| } | ||
|
|
||
| // Async returns whether the request expects a response. | ||
| func (req baseCallRequest) Async() bool { | ||
| return req.call.Async() | ||
| } | ||
|
|
||
| // Response creates a response for the request. | ||
| func (req baseCallRequest) Response(header tarantool.Header, | ||
| body io.Reader) (tarantool.Response, error) { | ||
| return req.call.Response(header, body) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.