Giter VIP home page Giter VIP logo

ports's Introduction

PORTS

Service that maintains ports data.

Overview

The logical structure of the service is reflected in a number of packages:

  • service: core package that maintains the business logic, updating and serving port data.
  • internal/parser: JSON parsing logic that provides the Feed interface that is used by the service to process bulk update of port details.
  • store: embedded key-value store (LMST) that is biased towards fast writes.
  • transport/rest: http service that interfaces the core service providing endpoints for client interaction.

The project is organised around the core service, which is 'surrounded' by various 'adapters' that depend on the domain constructs defined by the service. Store, and transport are such adapters. This allows the adapters to be replaced by a different mechanism, for example the transport with a new adapter that works from the file system instead of processing http requests.

Running the service

Directly (compiled from source)

Assuming that go >= 1.15 is present and you're in the ./cmd directory:

  • Download dependencies
go get ./...
  • Build the executable
go build -o ports
  • Run the service
./ports -db_path=<path-for-database-files>

The service listens on port 8000 by default, that can be overridden by the addr parameter.

Docker

From the project root directory:

  • Build the container
docker build . -t ports
  • Run the service in the container (exposing port 8000)
docker run --rm --name ports -p:8000:8000 ports

HTTP Endpoints

POST /ports

Allows a client to upload a json structure as defined in the original task description. The JSON input is parsed as a stream. Existing entries are overwritten by the provided update.

Example (where ports.json contains the updates):

curl -v 'localhost:8000/ports' [email protected]

GET /ports

Allows a client to retrieve port information. Provides an array of port objects ordered by port UN/LOCODE. Partial or paginated results are retrieved by providing from_id and limit parameters. If from_id is not provided then the first N entry is returned where N is defined by the limit parameter. If limit is not provided, then the maximum number of returned entries will be set to 1000.

curl -v 'localhost:8000/ports?from_id=ZWBUQ?limit=2'
[
  {
    "ID": "ZWHRE",
    "Details": {
      "name": "Harare",
      "city": "Harare",
      "country": "Zimbabwe",
      "coordinates": [
        31.03351,
        -17.8251657
      ],
      "province": "Harare",
      "timezone": "Africa/Harare",
      "unlocs": [
        "ZWHRE"
      ]
    }
  },
  {
    "ID": "ZWUTA",
    "Details": {
      "name": "Mutare",
      "city": "Mutare",
      "country": "Zimbabwe",
      "coordinates": [
        32.650351,
        -18.9757714
      ],
      "province": "Manicaland",
      "timezone": "Africa/Harare",
      "unlocs": [
        "ZWUTA"
      ]
    }
  }
]

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.