Hello: use const for magic strings

This commit is contained in:
vinchent 2024-09-10 11:16:15 +02:00
parent cbd4cf628f
commit 5e32007c89

View File

@ -2,11 +2,16 @@ package main
import "fmt" import "fmt"
const (
englishHelloPrefix = "Hello "
englishDefaultHelloName = "world"
)
func Hello(name string) string { func Hello(name string) string {
if name == "" { if name == "" {
return "Hello world" return englishHelloPrefix + englishDefaultHelloName
} }
return fmt.Sprintf("Hello %s", name) return fmt.Sprintf("%s%s", englishHelloPrefix, name)
} }
func main() { func main() {