package main
import "fmt"
type Status int
const (
StatusPending Status = iota // 0
StatusActive // 1
StatusArchived // 2
StatusDeleted // 3
)
// Implementing Stringer makes %s print the friendly name
func (s Status) String() string {
return [...]string{"pending", "active", "archived", "deleted"}[s]
}
// Bitflags — shift iota by 1 each time
type Perm int
const (
Read Perm = 1 << iota // 1
Write // 2
Execute // 4
)
func main() {
fmt.Println(StatusActive) // active
fmt.Println(StatusPending + 1) // active
p := Read | Write
fmt.Printf("%b can read: %t\n", p, p&Read != 0) // 11 can read: true
}
Create a free account and build your private vault. Share publicly whenever you want.