32

Loc2country – Location coordinates to country in microseconds

 5 years ago
source link: https://www.tuicool.com/articles/hit/EN7nmun
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Loc2Country

Location coordinates (lat/lon) to ISO alpha-3 country code. Responds in microseconds.

Manual

Input format: latitude, longitude

Output format: 3-letter-ISO-country-code, time-taken-to-respond-in-nanos

HowTo

  1. Run start.sh
  2. This will start a TCP server (localhost:3333) by default.
  3. Connect to the server by using telnet. (eg: "telnet localhost 3333")
  4. Input lat and lon seperated by comma, returns 3 letter country code and time taken to respond in nanoseconds.

Compiling

To compile, run:

go build src/server.go

To compile for a Linux machine from Mac, run (with correct architecture):

env GOOS=linux GOARCH=amd64 go build src/server.go

Testing

To test, run:

go test

Example

Starting the server:

$ sh start.sh 
2016/08/18 23:30:07 Creating server with address localhost:3333
2016/08/18 23:30:07 Loading data..
2016/08/18 23:30:13 Loading complete.
2016/08/18 23:30:13 Total Entries: 5235316
2016/08/18 23:30:13 Boot time: 5 seconds
$ telnet 127.0.0.1 3333
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
12,77
IND,17176

Contributors

Sooraj B - @soorajb

Ashwin Nair - @ashwin711

Harikrishnan Shaji - @hihari777

License

MIT License


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK