Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions v2/guestbook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link

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.

}
req.Header.Add("Content-Type", "application/json")
// add headers
Expand All @@ -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()

Expand Down Expand Up @@ -267,6 +270,24 @@ func findRedisURL() string {
return ""
}

//getDummyTone is a dummy version for the tone anylyzer
Copy link

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The 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()
Expand Down