Hello: use const for magic strings
This commit is contained in:
parent
cbd4cf628f
commit
5e32007c89
9
hello.go
9
hello.go
@ -2,11 +2,16 @@ package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
englishHelloPrefix = "Hello "
|
||||
englishDefaultHelloName = "world"
|
||||
)
|
||||
|
||||
func Hello(name string) string {
|
||||
if name == "" {
|
||||
return "Hello world"
|
||||
return englishHelloPrefix + englishDefaultHelloName
|
||||
}
|
||||
return fmt.Sprintf("Hello %s", name)
|
||||
return fmt.Sprintf("%s%s", englishHelloPrefix, name)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user