Last active
August 29, 2015 14:00
-
-
Save nicksnyder/11075664 to your computer and use it in GitHub Desktop.
Enum in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This should be in a color/ directory (but gists don't allow subdirectories) | |
package color | |
var ( | |
Red = Color{"red"} | |
Blue = Color{"blue"} | |
) | |
type Color struct { | |
name string | |
} | |
func (c *Color) Name() string { | |
return c.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"./color" | |
) | |
func printColor(c color.Color) { | |
fmt.Println(c.Name()) | |
} | |
func main() { | |
printColor(color.Red) | |
printColor(color.Blue) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment