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

Use net.TCPAddr to extract remote IP address #101

Merged
merged 1 commit into from
Dec 29, 2017

Conversation

corny
Copy link
Contributor

@corny corny commented Aug 11, 2017

No description provided.

@coveralls
Copy link

coveralls commented Aug 11, 2017

Coverage Status

Coverage increased (+0.3%) to 81.868% when pulling f5cdbb9 on digineo:tcpaddr into 769512c on jlaffaye:master.

if err != nil {
return nil, err
}
remoteAddr := tconn.RemoteAddr().(*net.TCPAddr)
Copy link
Owner

Choose a reason for hiding this comment

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

What it the conversion fails ?

Copy link
Contributor Author

@corny corny Aug 12, 2017

Choose a reason for hiding this comment

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

It can never fail, because we do net.DialTimeout("tcp", ...) before and thus it is always a TCPAddr.

Copy link
Owner

Choose a reason for hiding this comment

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

Well, it is not guaranteed at compile time, so I'd prefer to have a check so it can never crash at runtime.
Even if it should never happen.

Copy link
Contributor Author

@corny corny Aug 12, 2017

Choose a reason for hiding this comment

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

If the check fails something must be terribly wrong. I would like to see the program panicing in that case. Do you accept a panic("type assertion failed")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlaffaye ping

@jlaffaye
Copy link
Owner

Well, what's the benefits of this change ?
If it does the same thing while losing type safety Im not very fond of it.

@corny
Copy link
Contributor Author

corny commented Aug 23, 2017

It avoids unnecessary conversion to string and parsing the string. As I already mentioned: It can never be anything than *net.TCPAddr. We also have tests to ensure that.

@corny
Copy link
Contributor Author

corny commented Dec 29, 2017

In case this behaviour ever changes in a future version of Go, our tests will indicate that.
I'd really appreciate to get this merged.

@jlaffaye jlaffaye merged commit c2fc7f0 into jlaffaye:master Dec 29, 2017
@corny
Copy link
Contributor Author

corny commented Dec 29, 2017

thanks for merging!

@corny corny deleted the tcpaddr branch December 29, 2017 17:40
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.

None yet

3 participants