forked from mbuchoff/hackathon_backend_230909
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (27 loc) · 1019 Bytes
/
Copy pathmain.go
File metadata and controls
36 lines (27 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/mbuchoff/hackathon_backend_230909/internal/dto"
"github.com/mbuchoff/hackathon_backend_230909/internal/handlers"
)
func main() {
// Start the web server using net/http
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Set the content type header
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
// Write the response body
json.NewEncoder(w).Encode(dto.Response{Message: "OK"})
})
// Post endpoint to receive the phrase to be translated
http.HandleFunc("/question", handlers.AnswerQuestion)
// Get endpoint to receive the english sentences
http.HandleFunc("/sentences", handlers.GetEnglishSentencesHandler)
// Post endpoint to receive the number of questions and the language of the questions
http.HandleFunc("/game", handlers.GameHandler)
// Start the web server
fmt.Println("API is running on port 9999")
http.ListenAndServe(":9999", nil)
}