3 ms·
It's the game of the mouse and the cat :-D We can change the package color like this : package color type Color interface { void() } type color s
by hamdouni 3y ago
It's the game of the mouse and the cat :-D
We can change the package color like this :
package color
type Color interface {
void()
}
type color struct {
v string
}
func (c color) void() {}
func (c color) String() string {
return c.v
}
var (
Red color = color{"red"}
Green color = color{"green"}
Blue color = color{"blue"}
)
- kiitos 3y agofunc fn(c color.Color) { switch c { case color.Red, color.Green, color.Blue: log.Printf("c=%#+v -- OK", c) default: log.Printf("c=%#+v -- should not be possible", c) } } func main() { var c color.Color fn(c) } Output: c=<nil> -- should not be possible :shrug: