| 📦 Hello 0368b85 k33g 3h ago | 1 | // Package hello greets somebody by name. |
| 2 | package hello |
| 3 | |
| 4 | import "strings" |
| 5 | |
| 6 | // world is who is greeted when nobody was named. A greeting is the one thing |
| 7 | // that should never come out half-written, and "Hello, !" is what an empty |
| 8 | // name produces if it is passed straight through. |
| 9 | const world = "world" |
| 10 | |
| 11 | // Greet returns a greeting for name. |
| 12 | // |
| 13 | // Surrounding whitespace is dropped, so a name that arrives from a form or a |
| 14 | // command line reads the same as one written by hand. A name that is empty, or |
| 15 | // only whitespace, is greeted as the world. |
| 16 | func Greet(name string) string { |
| 17 | name = strings.TrimSpace(name) |
| 18 | if name == "" { |
| 19 | name = world |
| 20 | } |
| 21 | return "Hello, " + name + "!" |
| 22 | } |