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