This project is a simple quiz application built with Golang. It includes a backend server that serves quiz questions and handles submissions, and a CLI client that allows users to take the quiz.
- User should be able to get questions with a number of answers
- User should be able to select just one answer per question.
- User should be able to answer all the questions and then post his/hers answers and get back how many correct answers they had, displayed to the user.
- User should see how well they compared to others that have taken the quiz, eg. "You were better than 60% of all quizzers"
- Play Quiz: Users can take a quiz, answer questions, and see their scores.
- CLI Interface: A command-line interface allows users to interact with the application.
- Golang: Backend and CLI implementation.
- Cobra: CLI framework for handling user inputs.
quiz-app/
├── backend/
│ ├── main.go
│ ├── server/
│ │ ├── handler.go
│ │ └── questions.go
├── cli/
│ ├── main.go
│ └── cmd/
│ ├── root.go
│ └── quiz.go
├── .gitignore
├── go.mod
├── go.sum
├── LICENSE
├── questions.json
└── README.md
- Go (Golang): Ensure you have Go installed. You can download it from golang.org.
-
Clone the repository:
git clone https://github.com/tunahandag/quiz-app.git cd quiz-app
-
Initialize Go modules:
go mod init quiz-app
-
Install dependencies:
go get github.com/spf13/cobra@latest
Start the backend server to serve quiz questions and handle submissions.
go run backend/main.go
Start the CLI application to interact with the quiz.
go run cli/main.go take
When you run the CLI application, you will start the quiz with the first question.
- Answer the questions displayed.
- View your score and how you compared to other users.
The backend server exposes the following API endpoints:
- GET /questions: Retrieve all quiz questions.
- POST /submit: Submit quiz answers and receive the score.
[
{
"id": 1,
"question": "What is the capital of France?",
"answers": ["Berlin", "Madrid", "Paris", "Lisbon"],
"correct": 2
},
{
"id": 2,
"question": "Which planet is known as the Red Planet?",
"answers": ["Earth", "Mars", "Jupiter", "Venus"],
"correct": 1
},
{
"id": 3,
"question": "What is the largest ocean on Earth?",
"answers": ["Atlantic Ocean", "Indian Ocean", "Arctic Ocean", "Pacific Ocean"],
"correct": 3
},
{
"id": 4,
"question": "Who wrote 'To Kill a Mockingbird'?",
"answers": ["Harper Lee", "Mark Twain", "Ernest Hemingway", "F. Scott Fitzgerald"],
"correct": 0
},
{
"id": 5,
"question": "What is the chemical symbol for gold?",
"answers": ["Au", "Ag", "Pb", "Fe"],
"correct": 0
}
]
If you wish to contribute to this project, please fork the repository and submit a pull request. We welcome all contributions, including bug fixes, new features, and improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or feedback, please contact:
- Tunahan Dağ: [email protected]
- GitHub: tunahandag