Skip to content

yookibooki/tashkent-metro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tashkent Metro API

This is a simple REST API written in Go for managing Tashkent Metro lines, stations, and schedules.

Project Structure

  • cmd/api/main.go: Entry point.
  • internal/: Private packages for config, database, models, repository, handlers.
  • migrations/: SQL migration files.
  • .env.example: Sample env file.

Setup

  1. Install Go and PostgreSQL.
  2. Install the migrate CLI tool:
    go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  3. Copy .env.example to .env and fill in your database connection details.
  4. Create the database specified in your .env file.
  5. Run the database migrations:
    # The database connection string should match your .env configuration
    migrate -database 'postgres://your_username:your_password@localhost:5432/your_db_name?sslmode=disable' -path migrations up
  6. Build the application: go build -o bin/api cmd/api/main.go
  7. Run the server: ./bin/api

Migrations

The project uses golang-migrate/migrate to manage database schema changes.

Apply all up migrations:

migrate -database 'postgres://user:password@host:port/dbname?sslmode=disable' -path migrations up

Rollback the last migration:

migrate -database 'postgres://user:password@host:port/dbname?sslmode=disable' -path migrations down 1

Example Requests

Use curl or Postman.

  • Get all lines: curl http://localhost:8080/api/v1/lines
  • Create line: curl -X POST -H "Content-Type: application/json" -d '{"name":"Yunusobod","color":"Blue"}' http://localhost:8080/api/v1/lines
  • Get line by ID: curl http://localhost:8080/api/v1/lines/1
  • Get stations for line: curl http://localhost:8080/api/v1/lines/1/stations
  • Similar for /stations and /schedules.

About

A small, idiomatic Go REST API for managing metro stations and lines.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published