-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push parameter encoding into
BackendConfiguration.Call
Now that we have a little more consistency throughout the library, here we modify `BackendConfiguration.Call` (temporarily renamed to `Call2` while we refactor) so that it can take parameter structs directly, then encode them. This allows us to remove this common boilerplate from every API call throughout the entire library: ``` go if params != nil { commonParams = ¶ms.Params body = &form.Values{} form.AppendTo(body, params) } ``` Temporarily though, only the `charge/` package has been converted over to show what it looks like before we convert everything. There is a little bit of type trickiness that allows this to happen, and which requires a somewhat advanced understanding of some Go language semantics. We define a `ParamsContainer` interface as this: ``` go type ParamsContainer interface { GetParams() *Params } ``` Then on the `Params` struct itself, we define an implementation: ``` go func (p *Params) GetParams() *Params { return p } ``` In Go, whenever a struct is embedded in another struct, the host inherits the function implementation of the struct which was embedded. Because every parameter struct in the library embeds `Params`, they all get a `GetParams` implementation and thus implement `ParamsContainer` automatically: ``` go type ChargeParams struct { Params `form:"*"` ... } ``` This allows us to take a `ParamsContainer` from `Call`. Most of this applies similarly for `ListParams`, and similarly `iter.go` also gets a `Query2` and `GetIter2` to keep everything compiling while we refactor everything. I did a little more refactoring in `iter.go` as well just because there was quite a few very bad names in there. If this patch lands, I'll probably refactor even more of it in a follow up.
- Loading branch information
Showing
4 changed files
with
135 additions
and
75 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
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