-
Notifications
You must be signed in to change notification settings - Fork 225
add dummy tone function in case no network connection for waston #49
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,8 @@ func getPrimaryTone(value string, headers http.Header) (tone string) { | |
| client := &http.Client{} | ||
| req, err := http.NewRequest("POST", "http://analyzer:80/tone", b) | ||
| if err != nil { | ||
| return "Error talking to tone analyzer service: " + err.Error() | ||
| return getDummyTone(value) | ||
| //return "Error talking to tone analyzer service: " + err.Error() | ||
| } | ||
| req.Header.Add("Content-Type", "application/json") | ||
| // add headers | ||
|
|
@@ -202,7 +203,9 @@ func getPrimaryTone(value string, headers http.Header) (tone string) { | |
|
|
||
| res, err := client.Do(req) | ||
| if err != nil { | ||
| return "Error detecting tone: " + err.Error() | ||
| //means waston service is not available, so call the built in dummy hard code one to demonstrate | ||
| return getDummyTone(value) | ||
| //return "Error detecting tone: " + err.Error() | ||
| } | ||
| defer res.Body.Close() | ||
|
|
||
|
|
@@ -267,6 +270,24 @@ func findRedisURL() string { | |
| return "" | ||
| } | ||
|
|
||
| //getDummyTone is a dummy version for the tone anylyzer | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some comments here to explain the thinking behind the HasPrefix checks? Meaning, why do you assume a word that starts with "s" is happy? And how does this work when you look for 's' on 275 and 281?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm.. I just want to return something to simulate tone analyzer which can show we call our version2 guest book. Line 281 is a typo, I should use other beginning instead of "s", eg: "w"-->worry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we do it based on certain words? Seems hard to be based on a prefix... Also, I'd prefer return some indication that we are using dummy tone to generate the tone so we know it is not watson that is so dumb. :) |
||
| func getDummyTone(value string) string { | ||
| if strings.HasPrefix(value, "s") || strings.HasPrefix(value, "h") { | ||
| return value + " (✿◠‿◠)" | ||
| } | ||
| if strings.HasPrefix(value, "t") || strings.HasPrefix(value, "c") { | ||
| return value + " (︶︿︶)" | ||
| } | ||
| if strings.HasPrefix(value, "f") || strings.HasPrefix(value, "s") { | ||
| return value + " (ง’̀-‘́)ง" | ||
| } | ||
| if strings.HasPrefix(value, "a") || strings.HasPrefix(value, "b") { | ||
| return value + " (ಠ_ಠ)" | ||
| } | ||
|
|
||
| return "No Tone Detected" | ||
|
|
||
| } | ||
| func main() { | ||
| // When using Redis, setup our DB connections | ||
| url := findRedisURL() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure user sees from guestbook UI the value is returned from dummy tone service as unable to talk to watson.