Added ql database
This commit is contained in:
25
main.go
25
main.go
@@ -14,35 +14,18 @@ func homePage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func handleRequests() {
|
||||
http.HandleFunc("/", randomQuestion)
|
||||
http.HandleFunc("/api/answer", answerHandler)
|
||||
http.HandleFunc("/", randomQuestionHandler)
|
||||
log.Fatal(http.ListenAndServe(":10000", nil))
|
||||
}
|
||||
|
||||
func main() {
|
||||
Questions = []Question{
|
||||
Question{Category: "Muzika", Question: "Koji kompozitor je stariji od Mozarta?", Answer1: "Haydn", Answer2: "Rizo Ruža", Answer3: "Wagner", Answer4: "Vatroslav Lisinski"},
|
||||
Question{Category: "Matematika", Question: "Beskonačno minus beskonačno - koliki je rezultat ?", Answer1: "0", Answer2: "Zavisi", Answer3: "2 beskonačna", Answer4: "Nedefinisano u matematici"},
|
||||
Question{Category: "Književnost", Question: "Ko je napisao djelo 'Idiot'?", Answer1: "Dostojevski", Answer2: "Decembarski", Answer3: "Lenjin", Answer4: "Branko Čopić"},
|
||||
}
|
||||
initializeQuestions()
|
||||
handleRequests()
|
||||
}
|
||||
|
||||
func randomQuestion(w http.ResponseWriter, r *http.Request) {
|
||||
func answerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
randomIndex := rand.Intn(len(Questions))
|
||||
question := Questions[randomIndex]
|
||||
json.NewEncoder(w).Encode(question)
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
Category string `json:"category"`
|
||||
Question string `json:"question"`
|
||||
Answer1 string `json:"answer1"`
|
||||
Answer2 string `json:"answer2"`
|
||||
Answer3 string `json:"answer3"`
|
||||
Answer4 string `json:"answer4"`
|
||||
}
|
||||
|
||||
// let's declare a global Questions array
|
||||
// that we can then populate in our main function
|
||||
// to simulate a database
|
||||
var Questions []Question
|
||||
|
||||
Reference in New Issue
Block a user