This is a simple REST API written in Go for managing Tashkent Metro lines, stations, and schedules.
cmd/api/main.go: Entry point.internal/: Private packages for config, database, models, repository, handlers.migrations/: SQL migration files..env.example: Sample env file.
- Install Go and PostgreSQL.
- Install the
migrateCLI tool:go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest - Copy
.env.exampleto.envand fill in your database connection details. - Create the database specified in your
.envfile. - 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
- Build the application:
go build -o bin/api cmd/api/main.go - Run the server:
./bin/api
The project uses golang-migrate/migrate to manage database schema changes.
migrate -database 'postgres://user:password@host:port/dbname?sslmode=disable' -path migrations upmigrate -database 'postgres://user:password@host:port/dbname?sslmode=disable' -path migrations down 1Use 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
/stationsand/schedules.