Code Monkey home page Code Monkey logo

transitland-server's Introduction

Interline Transitland Server

GoDoc Go Report Card

Table of Contents

Installation

cd cmd/tlserver && go install .

Usage

The resulting tlserver binary includes several core commands from transitland-lib and adds the server command.

The main subcommands are:

Usage as a web service

To start the server with the REST API endpoints, GraphQL API endpoint, GraphQL explorer UI, and image generation endpoints:

tlserver server --dburl "postgres://your_host/your_database"

Alternatively, the database connection string can be specified using TL_DATABASE_URL environment variable. For local development environments, you will usually need to add ?sslmode=disable to the connection string.

Open http://localhost:8080/ in your web browser to see the GraphQL browser, or use the endpoints at /query or /rest/...

The "example" server instance configured by the tlserver command runs without authentication or authorization. Auth configuration is beyond the scope of this example command but can be added by configuring the server in your own package and adding HTTP middlewares to set user context and permissions data. You can use cmd/tlserver/main.go as an example to get started; it uses only public APIs from this package. (Earlier versions of tlserver included more built-in auth middlewares, but in our experience these are almost always custom per-installation, and were removed from this repo.) Additionally, this example server configuration exposes Go profiler endpoints on /debug/pprof/....

Development

  1. Install go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  2. On macOS, you will need the GNU timeout command: brew install coreutils
  3. You will also need GDAL tools for importing reference data sets: apt-get install gdal-bin, or brew install gdal-bin, etc.
  4. Check out github.com/interline-io/transitland-lib which contains the necessary schema and migrations.
  5. Set TL_TEST_SERVER_DATABASE_URL to the connection string to a test database
    • e.g. postgresql://localhost:5432/tlv2_test_server?sslmode=disable
    • You must also set PGHOST=localhost, PGDATABASE=tlv2_test_server, etc., to match this url
    • This requirement may be removed in the future
  6. Initialize test database schema: transitland-lib/internal/schema/postgres/bootstrap.sh
    • This will create the tlv2_test_server database in postgres
    • Will halt with an error (intentionally) if this database already exists
    • Runs golang-migrate on the migrations in transitland-lib/internal/schema/postgres/migrations
    • Unpacks and imports the Natural Earth datasets bundled with transitland-lib
  7. Initialize test fixtures: ./testdata/test_setup.sh
    • Builds and installs the cmd/tlserver command
    • Sets up test feeds contained in testdata/server/server-test.dmfr.json
    • Fetches and imports feeds contained in testdata/external
    • Creates additional fixtures defined in testdata/test_supplement.pgsql
    • Note that temporary files will be created in testdata/tmp; these are excluded in .gitignore
  8. Optional: Set TL_TEST_REDIS_URL to run some GBFS tests
  9. Optional: Set TL_TEST_FGA_ENDPOINT to a running OpenFGA server to run authorization tests
  10. Run all tests with go test -v ./...

Test cases generally run within transactions; you do not need to regenerate the fixtures unless you are testing migrations or changes to data import functionality.

Licenses

transitland-server is released under a "dual license" model:

  • open-source for use by all under the GPLv3 license
  • also available under a flexible commercial license from Interline

transitland-server's People

Contributors

dependabot[bot] avatar drewda avatar irees avatar toofishes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.