Geo Package First Take#2
Conversation
|
| t.Fatal(fmt.Errorf("embedFS.Open: %w", err)) | ||
| } | ||
|
|
||
| maximind, err := NewMaxMindReader(file) |
There was a problem hiding this comment.
should it be something like geo.NewMaxMindReader?
There was a problem hiding this comment.
it should, i will add it
| func (m *Reader) IsTestDB() bool { | ||
| desc, ok := m.Reader.Metadata().Description["en"] | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| return strings.Contains(desc, "Test Database") | ||
| } |
There was a problem hiding this comment.
why do we need to test if db is test DB?
There was a problem hiding this comment.
oh, got it. We use it for testing, to parse specific IPs.
There was a problem hiding this comment.
it is a sanity check for consumer , so they know if they are using test DB for production or not
There was a problem hiding this comment.
When/How a test db could be initialized versus a regular db?
There was a problem hiding this comment.
nit: imho, whoever is calling the reader should know if it's a test environment or not. There's no benefit for the reader to know that information itself.
| var embedFS embed.FS | ||
|
|
||
| const ( | ||
| maxmindCountryTestDB string = "test/MaxMind-DB/test-data/GeoIP2-Country-Test.mmdb" // test database, only covers NA, EU, AS continents |
There was a problem hiding this comment.
oh, this is just a link. We don't keep actual binary. Cool!
There was a problem hiding this comment.
this is a submodule link, the repo still keeps the test db binary, however when you install the package, you are not going to get db binary as part of the golang library.
|
|
||
| // CountryAlpha3Code - return 3-letter ISO code for country | ||
| func (c Country) CountryAlpha3Code() string { | ||
| if c.isEmpty() || len(c.Country.IsoCode) != 2 { |
There was a problem hiding this comment.
we can create a new func
e.g.
func (c Country) isCountryAlpha2Code() bool {
return c.isEmpty() || len(c.Country.IsoCode) != 2
}There was a problem hiding this comment.
nice! but i think the better name i think is isCountryAlpha2CodeValid()
| version: 2.1 | ||
|
|
||
| orbs: | ||
| codecov: codecov/codecov@3.2.5 |
There was a problem hiding this comment.
we do
- codecov is a nice-to-have, i want the data to be reflected as badge
- git is nice-to-have since it uses submodule, without git orb, i have to write my own submodule sync, just a simple helper
| "github.com/oschwald/geoip2-golang" | ||
| ) | ||
|
|
||
| // Country - a type definition on geoip2.Country data struct while providing heloer functions to retrieve certain data in convinent way and additional country data maxmind db does not provide |
There was a problem hiding this comment.
nit: providing heloer -> providing helper
| jobs: | ||
| unit-test: | ||
| docker: | ||
| - image: cimg/go:1.21.1 |
There was a problem hiding this comment.
Where is the cimg/go coming from?
Can we switch to chainguard if we need to use a public image? https://edu.chainguard.dev/chainguard/chainguard-images/reference/go/
There was a problem hiding this comment.
-
cimage is the circle ci's golang image
-
any specific reason you want to use chainguard image? any major benefit?
There was a problem hiding this comment.
@diogogmt ok, this is interesting
https://edu.chainguard.dev/chainguard/chainguard-images/vuln-comparison/go/
i like this - however, there is a few things to consider
- this image does not have built-in
curl, i have to install it - i do not see how security is going to impact this package, we are not building an app container, it is just there to run dagger
- cimage so far is the most convenient image so i do not have add extra steps to install tool chains to make things work
There was a problem hiding this comment.
Fair enough. If it's the official image by CircleCI with some helper already installed sounds good to me 👍
| resource_class: small | ||
| steps: | ||
| - checkout | ||
| - git/checkout-with-submodules |
There was a problem hiding this comment.
as specified in presentation, without submodules, you can not use the test db file provided by MaxMind which is required in unit testing
https://github.com/maxmind/MaxMind-DB
I try to avoid copy-and-paste and if more feature is added to the repo, i can easily grab different test db for unit testing since i have a submodule for all of its test db
| command: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sudo sh; cd -; } | ||
| - run: | ||
| name: unit test | ||
| command: dagger run --progress plain go run ci/main.go --cov_file cov.out |
| @@ -0,0 +1,3 @@ | |||
| [submodule "test/MaxMind-DB"] | |||
| @@ -1,2 +1,83 @@ | |||
| # geo | |||
| provide a simple interface to provide geo-related data, support maxmind db only at the moment | |||
| # Geo Information Library For Go | |||
| "github.com/oschwald/geoip2-golang" | ||
| ) | ||
|
|
||
| // Country - a type definition on geoip2.Country data struct while providing heloer functions to retrieve certain data in convinent way and additional country data maxmind db does not provide |
There was a problem hiding this comment.
suggestion: can you run the comments through a spell checker? eg; heloer -> helper
There was a problem hiding this comment.
@diogogmt do you have a tool for this? my spell checker does not work on ReadMe
There was a problem hiding this comment.
nvm, i found a vs code plugin, have run through a check, fixed the wording issue
| ) | ||
|
|
||
| // Country - a type definition on geoip2.Country data struct while providing heloer functions to retrieve certain data in convinent way and additional country data maxmind db does not provide | ||
| // user is expected not to directly modify it. |
There was a problem hiding this comment.
If the user shouldn't modify it, why is it public instead of private?
There was a problem hiding this comment.
because the design is - users still can access its internal data if they have more use case, and since the underlying structure is referred to a 3rd party package, it is not quite impossible to do so.
even you make it type country , you can still modify its internal, it is just user can not create a default country for their own
i will change it type country, since i do not expect user to create an empty Country struct
| } | ||
|
|
||
| func NewMaxMind(b []byte) (*Reader, error) { | ||
| reader, err := geoip2.FromBytes(b) |
There was a problem hiding this comment.
This block of code overlaps with https://github.com/blockthrough/geo/pull/2/files#diff-d607e19697d2bc59fe4217b2de67b083970a90c4ac563ca72891bd13c4c052baR24
suggestion: reference a private function to read the bytes from geoip2.
| return time.Unix(int64(m.Metadata().BuildEpoch), 0) | ||
| } | ||
|
|
||
| // Version - the opinionated semanic version for the underlying MaxMind DB in the format of v<major_version>.<minor_version> |
Change Set