26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go の Enum

Last updated at Posted at 2014-05-04

iota で Stringer な Enum はこんな感じだろうか。

package main

import (
	"log"
)

func init() {
	log.SetFlags(log.Lshortfile)
}

type Indexing int

func (i Indexing) String() string {
	switch i {
	case WITH:
		return "WITH"
	case WITHOUT:
		return "WITHOUT"
	case NEVER:
		return "NEVER"
	}
	log.Fatal("can't be here")
	return ""
}

const (
	WITH Indexing = iota
	WITHOUT
	NEVER
)

func main() {
	log.Println(WITH, WITHOUT, NEVER)
}
26
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?