An online questionnaire platform built with Go and Fiber. This project includes an API for creating and managing questionnaires, with support for hot reloading using air
and API documentation using Swagger.
- Features
- Requirements
- Setup Instructions
- Running the Project
- API Documentation
- Project Structure
- Environment Variables
- Contributing
- RESTful API built with Go and Fiber
- Middleware for authentication and logging
- Swagger integration for API documentation
- PostgreSQL database for data persistence
- Hot reloading with
air
- Go 1.20+
- PostgreSQL 14+
- Air for live reloading
- Docker (Optional) for containerized development
git clone https://github.com/yourusername/online_questionnaire.git
cd online_questionnaire
Ensure Go modules are enabled:
go mod tidy
Create a .env
file in the root directory and add the following variables:
APP_NAME=OnlineQuestionnaire
DEBUG=true
DB_USER=admin
DB_PASSWORD=admin123
DB_NAME=questionnaire
DB_HOST=localhost
DB_PORT=5432
DB_SSLMODE=disable
SERVER_HOST=localhost
SERVER_PORT=8080
Ensure PostgreSQL is running. Then, create the database:
CREATE DATABASE questionnaire;
Run migrations if applicable.
-
Install
air
globally if not already installed:go install github.com/cosmtrek/air@latest
-
Run the project with
air
:air
This will enable hot reloading. Any changes made to
.go
files in the watched directories will automatically trigger a rebuild and restart the application.
You can also run the project directly with Go:
go run cmd/app/main.go
Swagger is used to generate API documentation.
-
Ensure the application is running.
-
Open your browser and navigate to:
http://localhost:8080/swagger/index.html
-
Install the Swagger generator:
go get -u github.com/swaggo/swag/cmd/swag
-
Generate Swagger documentation:
swag init --generalInfo cmd/app/main.go
-
The generated files will appear in the
docs
directory.
online_questionnaire/
├── cmd/
│ └── app/
│ └── main.go # Application entry point
├── configs/ # Configuration files
├── docs/ # Swagger documentation
├── internal/
│ ├── db/ # Database setup and migrations
│ ├── handlers/ # API handlers
│ ├── middlewares/ # Middleware functions
│ ├── models/ # Data models
│ ├── repositories/ # Database interaction layer
│ ├── services/ # Business logic
├── scripts/ # Utility scripts for automation
├── tmp/ # Temporary files (ignored in version control)
├── .air.toml # Air configuration
├── .env # Environment variables
├── go.mod # Go modules
└── README.md # Project documentation
The project requires the following environment variables:
Variable | Description | Example |
---|---|---|
APP_NAME |
Name of the application | OnlineQuestionnaire |
DEBUG |
Enable debug mode (true/false) | true |
DB_USER |
Database username | admin |
DB_PASSWORD |
Database password | admin123 |
DB_NAME |
Database name | questionnaire |
DB_HOST |
Database host | localhost |
DB_PORT |
Database port | 5432 |
DB_SSLMODE |
Database SSL mode | disable |
SERVER_HOST |
Server host | localhost |
SERVER_PORT |
Server port | 8080 |
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Push to the branch.
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.
Let me know if you need additional adjustments or explanations!