Skip to content

Instantly share code, notes, and snippets.

@nicksnyder
Last active August 29, 2015 14:00
Show Gist options
  • Save nicksnyder/11075664 to your computer and use it in GitHub Desktop.
Save nicksnyder/11075664 to your computer and use it in GitHub Desktop.
Enum in Go
// 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
}
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