Giter Site home page Giter Site logo

ports's Introduction

Ports

This repo contains a sample implementation of the port domain service, as an HTTP API, and as described in technical instructions.

Build and run tests

To build the project, use the following command:

make build    # build the service.

You can run project tests using the following command:

make test      # go test with caching disabled and code coverage.

Note that, by default, only unit and short tests are executed. To run integration tests, you must first set up a service environment. You can do so with the following command:

make up   # set up an environment with service and its dependencies

You can then run integration tests by setting the MongoDB database connection URI in the appropriate environment variable:

PORTS_MONGODB_CONN_URI=mongodb://localhost:27017/papaya make test  

To destroy and clean up the service environment, use:

make down   # stop the service environment, clean up containers, networks, volumes

The Makefile includes a variety of other useful targets. Simply typing make should list all possible options.

Flags and Environment variables

The following command-line flags or environment variables can be used to configure the ports HTTP API.

Flag Description Environment variable Default value
-http-listen-addr HTTP listener address PORTS_HTTP_LISTEN_ADDR :80
-mongodb-conn-uri MongoDB connection URI PORTS_MONGODB_CONN_URI mongodb://localhost:27017/ports

File loader

Apart from the HTTP API, the project contains a separate command-line utility, called portload , which can be used to read and parse ports information from JSON files, as described in technical instructions. You can build portload into an executable using the following command:

go build -o portload ./cmd/portload

Running the file loader

To run the file loader, provide the path to a JSON file using a command-line flag. For example, to import the ports JSON file ports.json residing in a folder named testdata, use:

portload -f testdata/ports.json

The file loader will begin printing the records parsed, prefixed with a record counter. E.g.

...
main 1: Port: {AEAJM Ajman 52000 Ajman United Arab Emirates Asia/Dubai}
main 2: Port: {AEAUH Abu Dhabi 52001 Abu Dhabi United Arab Emirates Asia/Dubai}
main 3: Port: {AEDXB Dubai 52005 Dubai United Arab Emirates Asia/Dubai}
main 4: Port: {AEFJR Al Fujayrah 52005 Al Fujayrah United Arab Emirates Asia/Dubai}
...
main 1629: Port: {ZMLUN Lusaka 79145 Lusaka Lusaka Zambia  Africa/Lusaka}
main 1630: Port: {ZWBUQ Bulawayo 79145 Bulawayo Bulawayo Zimbabwe Africa/Harare}
main 1631: Port: {ZWHRE Harare 79145 Harare Harare Zimbabwe Africa/Harare}
main 1632: Port: {ZWUTA Mutare 79145 Mutare Manicaland Zimbabwe Africa/Harare}

Malformed records

Note that the file loader will immediately stop processing the file on the first error it encounters.

ports's People

Contributors

christgf avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.