1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package main import "math" func parseConstant(s string) (float64, error) { switch s { case "pi": return math.Pi, nil case "e": return math.E, nil } return 0, InvalidConstantErr{s} } type InvalidConstantErr struct { s string } func (e InvalidConstantErr) Error() string { return "invalid constant: " + e.s }