1、示例

// DataType is defined for the different types
type DataType byte

// for out use
const (
	KV DataType = iota
	LIST
	HASH
	SET
	ZSET
)

func (d DataType) String() string {
	switch d {
	case KV:
		return KVName
	case LIST:
		return ListName
	case HASH:
		return HashName
	case SET:
		return SetName
	case ZSET:
		return ZSetName
	default:
		return "unknown"
	}
}

但是不能像传统enum那种DataType.SET那样用。

相关文章: