A RESTful API server for the Act Planner application built with Go, Gin, and PostgreSQL.
- User authentication with JWT
- Event management
- Act scheduling and management
- Contact management
- Asset management
- RESTful API following the OpenAPI specification
- Go 1.21 or higher
- PostgreSQL 14 or higher
- Docker (optional, for containerized deployment)
-
Install Go:
- For Ubuntu/Debian:
sudo apt-get install golang - For macOS with Homebrew:
brew install go - For Windows: Download from golang.org
- Alternatively, use gvm to manage Go versions
- For Ubuntu/Debian:
-
Verify installation:
go version
-
Install PostgreSQL:
- For Ubuntu/Debian:
sudo apt-get install postgresql postgresql-contrib - For macOS with Homebrew:
brew install postgresql - For Windows: Download from postgresql.org
- For Ubuntu/Debian:
-
Start PostgreSQL service:
- Ubuntu/Debian:
sudo service postgresql start - macOS:
brew services start postgresql - Windows: PostgreSQL is installed as a service and starts automatically
- Ubuntu/Debian:
-
Create a database:
sudo -u postgres createdb act_planner
-
Create a user (optional):
sudo -u postgres psql -c "CREATE USER actplanner WITH PASSWORD 'your_password';" sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE act_planner TO actplanner;"
-
Install Docker:
- Follow instructions at docker.com
-
Run PostgreSQL container:
docker run --name act-planner-postgres \ -e POSTGRES_PASSWORD=postgres \ -e POSTGRES_DB=act_planner \ -p 5432:5432 \ -d postgres:14
-
Clone the repository:
git clone https://github.com/ankk98/act-planner-backend.git cd act-planner-backend -
Install dependencies:
go mod download go mod tidy
-
Configure environment variables:
cp .env.example .env
Edit
.envwith your database configuration:DB_HOST=localhost DB_PORT=5432 DB_USER=postgres # or your custom user DB_PASSWORD=postgres # your password DB_NAME=act_planner DB_SSL_MODE=disable -
Run database migrations:
go run cmd/migrate/main.go
-
Start the server:
go run cmd/server/main.go
The server will start on http://localhost:8080 by default.
-
Make sure the database is set up and the server is running.
-
Run all tests:
go test ./tests/... -
Run specific test:
go test ./tests/api/auth_test.go -
Run tests with verbose output:
go test -v ./tests/...
You can use curl to test the API endpoints:
-
Register a new user:
curl -X POST -H "Content-Type: application/json" \ -d '{"name":"Test User","email":"[email protected]","password":"password123"}' \ http://localhost:8080/api/v1/auth/register
-
Login:
curl -X POST -H "Content-Type: application/json" \ -d '{"email":"[email protected]","password":"password123"}' \ http://localhost:8080/api/v1/auth/login
-
Get user profile (with token):
TOKEN="your_jwt_token" curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/v1/users/me
The API follows the specifications defined in backend_api_specifications.md.
.
├── cmd/ # Application entry points
│ ├── migrate/ # Database migration tool
│ └── server/ # API server
├── config/ # Configuration
├── internal/ # Private application code
│ ├── api/ # API-related code
│ │ ├── handlers/ # Request handlers
│ │ ├── middleware/ # HTTP middleware
│ │ └── routes/ # Route definitions
│ ├── models/ # Data models
│ ├── repository/ # Data access layer
│ └── services/ # Business logic
├── pkg/ # Public libraries
│ ├── auth/ # Authentication utilities
│ ├── database/ # Database utilities
│ └── utils/ # General utilities
├── tests/ # Test files
│ ├── api/ # API tests
│ └── integration/ # Integration tests
└── storage/ # File storage (gitignored)
MIT