@@ -4,22 +4,53 @@ import (
44 "fmt"
55 "log"
66 "net/http"
7+ "markdown-note-taking-app/notes"
78)
89
910
10- func apiHandler (w http.ResponseWriter , r * http.Request ) {
11- fmt .Fprint (w , "Hello, World!" )
11+ func createNote (w http.ResponseWriter , r * http.Request ) {
12+ fmt .Fprint (w , "Create note" )
13+ }
14+
15+ func checkGrammarAndSpelling (w http.ResponseWriter , r * http.Request ) {
16+ fmt .Fprint (w , "Check grammar and spelling" )
17+
18+ }
19+
20+ func listNotes (w http.ResponseWriter , r * http.Request ) {
21+ fmt .Fprint (w , "List notes" )
22+ }
23+
24+ func readNote (w http.ResponseWriter , r * http.Request ) {
25+ fmt .Fprint (w , "Read note" )
26+ }
27+
28+ func deleteNote (w http.ResponseWriter , r * http.Request ) {
29+ fmt .Fprint (w , "Delete note" )
30+ }
31+
32+ func updateNote (w http.ResponseWriter , r * http.Request ) {
33+ fmt .Fprint (w , "Update note" )
1234}
1335
1436func startFrontendServer () {
15- fs := http .FileServer (http .Dir ("frontend" ))
37+ fs := http .FileServer (http .Dir ("frontend" ))
1638 http .Handle ("/" , fs )
1739 log .Fatal (http .ListenAndServe (":80" , nil ))
1840}
1941
2042func startBackendServer () {
21- http .HandleFunc ("/api" , apiHandler )
22- log .Fatal (http .ListenAndServe (":8080" , nil ))
43+ // todo change to router and use verbs GET, POST, PUT, DELETE
44+
45+ mux := http .NewServeMux ()
46+ mux .HandleFunc ("/api/createNote" , createNote )
47+ mux .HandleFunc ("/api/upload" , notes .UploadHandler )
48+ mux .HandleFunc ("/api/checkGrammarAndSpelling" , checkGrammarAndSpelling )
49+ mux .HandleFunc ("/api/listNotes" , listNotes )
50+ mux .HandleFunc ("/api/readNote" , readNote )
51+ mux .HandleFunc ("/api/deleteNote" , deleteNote )
52+ mux .HandleFunc ("/api/updateNote" , updateNote )
53+ log .Fatal (http .ListenAndServe (":8080" , mux ))
2354
2455}
2556
0 commit comments