|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "azuretextanalysis" |
| 5 | + "html/template" |
| 6 | + "net/http" |
| 7 | +) |
| 8 | + |
| 9 | +var ( |
| 10 | + api string = "" |
| 11 | + resource string = "" |
| 12 | + documents = []map[string]string{ |
| 13 | + {"id": "1", "language": "en", "text": "This is a super cool test for my super cool package."}, |
| 14 | + {"id": "2", "language": "en", "text": "This is a stupid test for my stupid package."}, |
| 15 | + {"id": "3", "language": "en", "text": "The DoD is a very big operation compared to Banner Health."}, |
| 16 | + {"id": "4", "language": "en", "text": "I really like CostCo chicken nuggets and German beer."}, |
| 17 | + } |
| 18 | +) |
| 19 | + |
| 20 | +// tmpl is the HTML template that drives the user interface. |
| 21 | +var tmpl = template.Must(template.New("tmpl").Parse(` |
| 22 | +<!DOCTYPE html> |
| 23 | + <html> |
| 24 | + <body> |
| 25 | + <center> |
| 26 | + <h1>Analyze</h1> |
| 27 | + <h2>{{.}}</h2> |
| 28 | +</center></body></html> |
| 29 | +`)) |
| 30 | + |
| 31 | +func main() { |
| 32 | + |
| 33 | + // Run Entities at `localhost:8080/entities` |
| 34 | + http.HandleFunc("/entities", func(w http.ResponseWriter, r *http.Request) { |
| 35 | + data := azuretextanalysis.Entities(api, resource, documents) |
| 36 | + |
| 37 | + err := tmpl.Execute(w, data) |
| 38 | + if err != nil { |
| 39 | + http.Error(w, err.Error(), http.StatusInternalServerError) |
| 40 | + } |
| 41 | + }) |
| 42 | + |
| 43 | + // Run Phrases at `localhost:8080/phrases` |
| 44 | + http.HandleFunc("/phrases", func(w http.ResponseWriter, r *http.Request) { |
| 45 | + data := azuretextanalysis.Phrases(api, resource, documents) |
| 46 | + |
| 47 | + err := tmpl.Execute(w, data) |
| 48 | + if err != nil { |
| 49 | + http.Error(w, err.Error(), http.StatusInternalServerError) |
| 50 | + } |
| 51 | + }) |
| 52 | + |
| 53 | + // Run Language at `localhost:8080/language` |
| 54 | + http.HandleFunc("/language", func(w http.ResponseWriter, r *http.Request) { |
| 55 | + data := azuretextanalysis.Language(api, resource, documents) |
| 56 | + |
| 57 | + err := tmpl.Execute(w, data) |
| 58 | + if err != nil { |
| 59 | + http.Error(w, err.Error(), http.StatusInternalServerError) |
| 60 | + } |
| 61 | + }) |
| 62 | + |
| 63 | + // Run Sentiment at `localhost:8080/sentiment` |
| 64 | + http.HandleFunc("/sentiment", func(w http.ResponseWriter, r *http.Request) { |
| 65 | + data := azuretextanalysis.Sentiment(api, resource, documents) |
| 66 | + |
| 67 | + err := tmpl.Execute(w, data) |
| 68 | + if err != nil { |
| 69 | + http.Error(w, err.Error(), http.StatusInternalServerError) |
| 70 | + } |
| 71 | + }) |
| 72 | + |
| 73 | + // Start listener |
| 74 | + http.ListenAndServe(":8080", nil) |
| 75 | +} |
0 commit comments