-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequency.go
More file actions
29 lines (26 loc) · 802 Bytes
/
Copy pathfrequency.go
File metadata and controls
29 lines (26 loc) · 802 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
package main
import (
"net/http"
"github.com/pkg/errors"
"github.com/thecsw/katya/analysis"
)
// frequencyFinder returns a word frequency table for a given source
func frequencyFinder(w http.ResponseWriter, r *http.Request) {
source := r.URL.Query().Get("source")
if source == "" {
httpJSON(w, nil, http.StatusBadRequest, errors.New("bad query"))
return
}
// whether we should serve a CSV file instead of a JSON
useCSV := r.URL.Query().Get("csv")
result, err := analysis.FindTheMostFrequentWords(source)
if err != nil {
httpJSON(w, nil, http.StatusInternalServerError, errors.Wrap(err, "oops"))
return
}
if useCSV == "1" {
httpCSVFreqResults(w, result, http.StatusOK)
return
}
httpJSON(w, analysis.FilterStopwordsSimple(result, analysis.StopwordsRU), http.StatusOK, nil)
}