-
Notifications
You must be signed in to change notification settings - Fork 25
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
v2.0.0 with API changes & up-to-date data #19
Conversation
Well, OK, some of the changes I want/need to make here really would be best done in a major version change, which under Go's versioning scheme will require a totally new import path ( |
- Add go.mod file; needed by language server. - Normalize some line lengths. - Add timezone. - Change import path. - Simpify gen script significantly.
c8eeed6
to
f6ccb81
Compare
in the process, delete all code operating and assuming old data structures. we will create new functions as necessary from scratch for these.
The API is significantly simplified now and I've added all new data types for the core & ASN APIs. Need to do this before merge:
After this I want to do #12 and #15 as separate PRs, then this SDK is on-par with the Python one. |
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.
I'm against ASN
⇒ Asn
renames:
Words in names that are initialisms or acronyms (e.g. "URL" or "NATO") have a consistent case. For example, "URL" should appear as "URL" or "url" (as in "urlPony", or "URLPony"), never as "Url". As an example: ServeHTTP not ServeHttp. For identifiers with multiple initialized "words", use for example "xmlHTTPRequest" or "XMLHTTPRequest".
This rule also applies to "ID" when it is short for "identifier" (which is pretty much all cases when it's not the "id" as in "ego", "superego"), so write "appID" instead of "appId".
Thanks @pshevtsov for the review! I think all of the I strongly disagree with the opinion on initialisms, to be frank. "XMLHTTPRPCRequest" is definitely not as readable as "XmlHttpRpcRequest", for example, and you certainly run into these kinds of things in the wild. But I'll stick with the Golang opinion on this, although there isn't some strong requirement we do so. |
For a single point of reference of $ golint ./ipinfo/
ipinfo/asn.go:7:6: exported type AsnDetails should have comment or be unexported
ipinfo/asn.go:23:6: exported type AsnDetailsPrefix should have comment or be unexported
ipinfo/cache.go:9:6: exported type Cache should have comment or be unexported
ipinfo/cache.go:14:1: exported function NewCache should have comment or be unexported
ipinfo/cache.go:18:6: exported type EvaluatorFunc should have comment or be unexported
ipinfo/cache.go:20:1: exported method Cache.GetOrRequest should have comment or be unexported
ipinfo/client.go:163:1: exported function SetCache should have comment or be unexported
ipinfo/client.go:167:1: exported method Client.SetCache should have comment or be unexported
ipinfo/client.go:173:1: exported function SetToken should have comment or be unexported
ipinfo/client.go:177:1: exported method Client.SetToken should have comment or be unexported
ipinfo/core.go:8:6: exported type Core should have comment or be unexported
ipinfo/core.go:9:2: struct field Ip should be IP
ipinfo/core.go:26:6: exported type CoreAsn should have comment or be unexported
ipinfo/core.go:34:6: exported type CoreCompany should have comment or be unexported
ipinfo/core.go:40:6: exported type CoreCarrier should have comment or be unexported
ipinfo/core.go:46:6: exported type CorePrivacy should have comment or be unexported
ipinfo/core.go:53:6: exported type CoreAbuse should have comment or be unexported
ipinfo/core.go:62:6: exported type CoreDomains should have comment or be unexported
ipinfo/core.go:63:2: struct field Ip should be IP
ipinfo/core.go:69:6: func GetIpInfo should be GetIPInfo
ipinfo/core.go:74:18: method GetIpInfo should be GetIPInfo
ipinfo/ipinfo.go:5:1: comment on exported var DefaultClient should be of the form "DefaultClient ..." |
For subdirs after clearing these:
|
Some more things to do:
|
@UmanShahzad You can run |
@UmanShahzad Maybe let's try to use |
Yea noticed that a bit late, hah 👍
I don't think that's useful for us given we basically just have 1-line scripts, and that this tool is really trying to be a Makefile replacement using Golang, which is really meant for running dependency-graph oriented tasks, not a simple lint or format task. edit: more simply, adding tools like that just increases our problems rather than actually solving anything. |
note that the in-mem impl is already concurrency-safe because the underlying library does use locks appropriately.
Note: another change we're making here is requiring cache implementations themselves to be concurrency-safe, because it doesn't make sense to handle locks/etc at a higher level when the underlying impl is already doing that. The included in-memory impl is already doing this, for example. |
@pshevtsov Can you give this a last look? I want to ship this by early next week at most. I didn't add explicit test cases; the examples have & and are currently serving as test cases just fine for now I suppose. |
@pshevtsov ping |
Will review today! |
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.
It's neither idiomatic nor necessary to put
Get
into the getter's name.
So, let's drop Get
from the following functions' names:
$ grep -re 'func.*Get[^(]' *
ipinfo/core.go:func GetIPInfo(ip net.IP) (*Core, error) {
ipinfo/core.go:func (c *Client) GetIPInfo(ip net.IP) (*Core, error) {
ipinfo/core.go:func GetIPAddr() (string, error) {
ipinfo/core.go:func (c *Client) GetIPAddr() (string, error) {
ipinfo/core.go:func GetIPHostname(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPHostname(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPCity(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPCity(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPRegion(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPRegion(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPCountry(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPCountry(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPLocation(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPLocation(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPOrg(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPOrg(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPPostal(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPPostal(ip net.IP) (string, error) {
ipinfo/core.go:func GetIPTimezone(ip net.IP) (string, error) {
ipinfo/core.go:func (c *Client) GetIPTimezone(ip net.IP) (string, error) {
ipinfo/asn.go:func GetASNDetails(asn string) (*ASNDetails, error) {
ipinfo/asn.go:func (c *Client) GetASNDetails(asn string) (*ASNDetails, error) {
WDYT?
Some of the examples fail for me:
|
This is talking about getters & setters for fields on a struct, like how it's often done in Java. The "GetX" functions here are not those kinds of functions.
I can see the benefit of a standardized form for a big, changing project, but for this very small-scoped project which will hardly change much after this PR and the existing issues, it doesn't seem necessary, and just gets in the way of being able to explain what we want without having to bin-pack our explanations into these categories.
We can upper-case, but let's keep the abbreviations; that's what the other SDKs do, and is what the API does.
👍
Thanks for catching that; it seems that since IPinfo returns text rather than a valid JSON string (which would have the text wrapped in I checked to see if we have something in the backend currently to give back actual JSON on e.g.
Sure but what is the alternative? Golang doesn't support method overload or default argument values. We would have to complicate the API significantly for this. Or the user would have to add an extra line to their code to call set methods for each of the missing fields. The function in question is also likely to be used in only 1 place throughout a user's codebase, or at least highly infrequently. Being explicit about what you want upfront by stating all the arguments seems perfectly reasonable to me for such a function. Golang by its design doesn't seem to have chosen to make this use case pretty in any case. |
To update my own point about "parsing text raw": nevermind that, we'll just make a normal request and then pick out the individual field. This will have the benefit of caching the entire IP data, so if another function is used for other data on that IP, it's cached. |
fix field-specific funcs so they dont req for specific data - they will get it all and just return the one piece from the resulting struct. this has the benefit of caching _all_ data for later use. also fix some naming schemes.
Thanks again for your review, @pshevtsov . I've fixed some of the naming issues and all the examples work now. I'm going to merge this now and consider v2.0.0 ready. |
Closes #13
Closes #16