example

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind demonstrates integer style enums

const (
	Kind1 Kind = iota
	Kind2
	KindX // Kind3
)

func (Kind) Bytes

func (k Kind) Bytes() []byte

Bytes returns a byte-level representation of String(). If !k.Defined(), then a generated string is returned based on k's value.

func (Kind) Defined

func (k Kind) Defined() bool

Defined returns true if k holds a defined value.

func (Kind) MarshalText

func (k Kind) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Kind) Next

func (k Kind) Next() Kind

Next returns the next defined Kind. If k is not defined, then Next returns the first defined value. Next() can be used to loop through all values of an enum.

k := Kind(0)
for {
	fmt.Println(k)
	k = k.Next()
	if k == Kind(0) {
		break
	}
}

The exact order that values are returned when looping should not be relied upon.

func (*Kind) Scan

func (k *Kind) Scan(scanState fmt.ScanState, verb rune) error

Scan implements fmt.Scanner. Use fmt.Scan to parse strings into Kind values

func (Kind) String

func (k Kind) String() string

String implements fmt.Stringer. If !k.Defined(), then a generated string is returned based on k's value.

func (*Kind) UnmarshalText

func (k *Kind) UnmarshalText(x []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type StrKind

type StrKind string

StrKind demonstrates string style enums

const (
	Hello StrKind = "Hello"
	World StrKind = "World"
	Bang  StrKind = "Bang" // Override
)

func (StrKind) Bytes

func (s StrKind) Bytes() []byte

Bytes returns a byte-level representation of String(). If !s.Defined(), then a generated string is returned based on s's value.

func (StrKind) Defined

func (s StrKind) Defined() bool

Defined returns true if s holds a defined value.

func (StrKind) MarshalText

func (s StrKind) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (StrKind) Next

func (s StrKind) Next() StrKind

Next returns the next defined StrKind. If s is not defined, then Next returns the first defined value. Next() can be used to loop through all values of an enum.

s := StrKind("")
for {
	fmt.Println(s)
	s = s.Next()
	if s == StrKind("") {
		break
	}
}

The exact order that values are returned when looping should not be relied upon.

func (*StrKind) Scan

func (s *StrKind) Scan(scanState fmt.ScanState, verb rune) error

Scan implements fmt.Scanner. Use fmt.Scan to parse strings into StrKind values

func (StrKind) String

func (s StrKind) String() string

String implements fmt.Stringer. If !s.Defined(), then a generated string is returned based on s's value.

func (*StrKind) UnmarshalText

func (s *StrKind) UnmarshalText(x []byte) error

UnmarshalText implements encoding.TextUnmarshaler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL