-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
32 lines (29 loc) · 779 Bytes
/
main.go
File metadata and controls
32 lines (29 loc) · 779 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
package main
import (
"net/http"
"encoding/json"
"github.com/gorilla/mux"
"github.com/tom1193/language-api/nlp"
"log"
//"github.com/tom1193/language-api/proto"
"github.com/rs/cors"
)
func GetEntityEndpoint(w http.ResponseWriter, req *http.Request) {
params := req.URL.Query()
if params["text"] != nil {
res, err := nlp.AnalyzeEntitySentiment(params["text"][0])
if err != nil {
log.Fatalf("Failed to analyze text: %v", err)
}
result := nlp.GenerateEntity(res)
json.NewEncoder(w).Encode(result)
} else {
log.Fatalf("Failed to parse query params")
}
}
func main () {
router := mux.NewRouter()
handler := cors.Default().Handler(router)
router.HandleFunc("/entity", GetEntityEndpoint).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", handler))
}