Skip to content
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

examples/basicauth: Simplify comma-ok type assertion in if statement. #558

Merged
merged 1 commit into from
Feb 18, 2017

Conversation

dmitshur
Copy link
Member

@dmitshur dmitshur commented Feb 18, 2017

According to https://golang.org/ref/spec#Type_assertions:

For an expression x of interface type and a type T, the primary expression

x.(T)

asserts that x is not nil and that the value stored in x is of type T. [...] The value of ok is true if the assertion holds.

Therefore, this if statement can be simplified without changing behavior.

I also made a proposal for this check in dominikh/go-tools#34.

According to https://golang.org/ref/spec#Type_assertions:

> For an expression x of interface type and a type T, the primary expression
>
> 	x.(T)
>
> asserts that x is not nil and that the value stored in x is of type T.
> [...]
> The value of ok is true if the assertion holds.

Therefore, this if statement can be simplified without changing behavior.
@dmitshur dmitshur force-pushed the basicauth-simplify-type-assertion branch from c232097 to a370a26 Compare February 18, 2017 21:09
dmitshur referenced this pull request Feb 18, 2017
Add a new error type, TwoFactorAuthError, which identifies the need to
include a one-time password when using Basic Auth for a user with
two-factor auth enabled.

An example of using both the new transport and error type can be seen in
examples/basicauth/main.go.

fixes #258
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you, @shurcooL.

@dmitshur dmitshur merged commit 2ec691a into master Feb 18, 2017
@dmitshur dmitshur deleted the basicauth-simplify-type-assertion branch February 18, 2017 23:40
bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
…google#558)

According to https://golang.org/ref/spec#Type_assertions:

> For an expression x of interface type and a type T, the primary expression
>
> 	x.(T)
>
> asserts that x is not nil and that the value stored in x is of type T. [...] The
> value of ok is true if the assertion holds.

Therefore, this if statement can be simplified without changing behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants