joplin-multi-note-viewer/server/server.go

50 lines
1.0 KiB
Go
Raw Permalink Normal View History

2022-02-21 18:04:18 +00:00
package main
import (
"net/http"
"github.com/gorilla/mux"
)
func searchHandler(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("q")
response, err := performSearch(query)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Issue querying Joplin! Is it running?"))
return
}
body, err := response.GetFrontendBody()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error serializing JSON!"))
return
}
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Write(body)
}
func noteHandler(w http.ResponseWriter, r *http.Request) {
noteID := mux.Vars(r)["id"]
response, err := retrieveNote(noteID)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Issue querying Joplin! Is it running?"))
return
}
body, err := response.GetFrontendBody()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Error serializing JSON!"))
return
}
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Write(body)
}