-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
74 lines (64 loc) · 2.16 KB
/
server.go
File metadata and controls
74 lines (64 loc) · 2.16 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
azuretextanalysis "azuretextanalysis/AzureTextAnalysis"
"html/template"
"net/http"
)
var (
api string = ""
resource string = ""
documents = []map[string]string{
{"id": "1", "language": "en", "text": "This is a super cool test for my super cool package."},
{"id": "2", "language": "en", "text": "This is a stupid test for my stupid package."},
{"id": "3", "language": "en", "text": "The DoD is a very big operation compared to Banner Health."},
{"id": "4", "language": "en", "text": "I really like CostCo chicken nuggets and German beer."},
}
)
// tmpl is the HTML template that drives the user interface.
var tmpl = template.Must(template.New("tmpl").Parse(`
<!DOCTYPE html>
<html>
<body>
<center>
<h1>Analyze</h1>
<h2>{{.}}</h2>
</center></body></html>
`))
func main() {
// Basic page calls to `localhost`
http.Handle("/", http.FileServer(http.Dir("./pages")))
// Run Entities at `localhost.com/entities`
http.HandleFunc("/entities", func(w http.ResponseWriter, r *http.Request) {
data := azuretextanalysis.Entities(api, resource, documents)
err := tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
// Run Phrases at `localhost.com/phrases`
http.HandleFunc("/phrases", func(w http.ResponseWriter, r *http.Request) {
data := azuretextanalysis.Phrases(api, resource, documents)
err := tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
// Run Language at `localhost.com/language`
http.HandleFunc("/language", func(w http.ResponseWriter, r *http.Request) {
data := azuretextanalysis.Language(api, resource, documents)
err := tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
// Run Sentiment at `localhost.com/sentiment`
http.HandleFunc("/sentiment", func(w http.ResponseWriter, r *http.Request) {
data := azuretextanalysis.Sentiment(api, resource, documents)
err := tmpl.Execute(w, data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
// Start listener
http.ListenAndServe(":8080", nil)
}