How to use a package which was created by other people?

Hi. I’m a front-end developer with basic PHP/MySQL knowledge. And Go is a new thing to me.

I’m trying to use a package which was created by other people.

The documentation of that package mentions commands like this one:

-block-file=[FILENAME]

Those commands look like Node.js commands. In the past, I used the Node.js things several times for the reason of SASS, uglify-js, etc, but I cannot recall completely how to use it at the moment. When it comes to these terminal things, it can be quite abstruse to a front-end developer like me.

I tried searching the answer on the internet and YouTube but couldn’t find step-by-step tutorials.

My operation system is Windows 7. I already installed Go in my D drive.

Let’s say I’m at desktop right now. Is the first step opening the Command Prompt?

Thats arguments to the binary you can compile from that repositories project.

If you only import the github.com/maxmind/geoip2-csv-converter/convert package, you won’t need to care for them.

Only if you want to use the program that is created using that source, you need to use those together with that executable.


Edit and PS: You should never close your terminal unless you need it to reload the environment. It should be the second most often used tool in programming, right after a simple editor which might even run in a terminal. No-one needs Blowclipse or IntelliHuge…

Thanks. If I understand correctly, those commands are not needed and the Command Prompt probably is not needed, neither.

That package has a documentation on GoDoc. Could you please let me know what the first step I need to do to use its ConvertFile function is?

import it, then call it, roughly:

package main

import "github.com/maxmind/geoip2-csv-converter/convert"

func main() {
  err = convert.ConvertFile("~/input.data", "~/output.data", true, false, false)
  if err != nil {
    panic(err)
  }
}

Save that file anywhere, then use your terminal to cd into where you saved that file and then do go run filename.

1 Like

Thank you for illustrating. The file I’m trying to convert is GeoLite2-City-Blocks-IPv4.csv. It is in a folder in my desktop. So I saved the converter.go file in the same folder.

Here is my converter.go:

package main

import "github.com/maxmind/geoip2-csv-converter/convert"

func main() {
  err = convert.ConvertFile("~/GeoLite2-City-Blocks-IPv4.csv", "~/GeoLite2-City-Blocks-IPv4-converted.csv", false, true, false)
  if err != nil {
    panic(err)
  }
}

But after I cd into the folder and ran go run converter.go, I got this message

converter.go:3:8: cannot find package "github.com/maxmind/geoip2-csv-converter/c
onvert" in any of:
        D:\Go\src\github.com\maxmind\geoip2-csv-converter\convert (from $GOROOT)

        C:\Users\Ian\go\src\github.com\maxmind\geoip2-csv-converter\convert (fro
m $GOPATH)

Yeah forgot about that. You need to go get github.com/maxmind/geoip2-csv-converter first.

But do you really need that file converted once, or do you need to convert files regularly programmatically?

If it’s the former just use the binary they provide from the GitHub releases and run it on a terminal providing the arguments described in the README.

1 Like

I need to convert only two files: GeoLite2-City-Blocks-IPv4.csv and GeoLite2-City-Blocks-IPv6.csv. And then I will import the two converted files into MySQL database. So I guess my situation is the former? If so, could you help check if the following command is correct?

-block-file=GeoLite2-City-Blocks-IPv4.csv -output-file=GeoLite2-City-Blocks-IPv4-converted.csv -include-range

Also, which “binary” should I use? And how to use?

That for your operating system. Just drop it where you need it and run it. Assuming the name of the executable is foo and you dropped it into the same folder as your data files then you’d run like this:

./foo -block-file=GeoLite2-City-Blocks-IPv4.csv -output-file=GeoLite2-City-Blocks-IPv4-converted.csv -include-range

Or with *-IPv6* respectively.

But this has nothing to do with go. Its basic terminal usage every programmer should know.

2 Likes

Thanks for helping checking the command. I don’t understand what executable I should drop into the folder. Where can I get the executable?

On GitHub. The “Releases” tab, as mentioned in the readme.

1 Like

Thank you very much! I just converted the two files successfully!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.