example

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

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
)

func (Kind) Bytes added in v0.0.6

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.

Example
fmt.Println(Kind(0).Defined())
fmt.Println(Kind(1).Defined())
fmt.Println(Kind(2).Defined())
Output:

true
true
false

func (Kind) MarshalJSON added in v0.0.6

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

MarshalJSON implements json.Marshaler

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.

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

Kind1
Kind2

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

Example
var s1, s2 StrKind
_, _ = fmt.Sscan("Hello World", &s1, &s2)
fmt.Println(s1)
fmt.Println(s2)
Output:

Hello
World

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) UnmarshalJSON added in v0.0.6

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

UnmarshalJSON implements json.Unmarshaler

type StrKind

type StrKind string

StrKind demonstrates string style enums

const (
	Hello StrKind = "Hello"
	World StrKind = "World"
)

func (StrKind) Bytes added in v0.0.6

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) MarshalJSON added in v0.0.6

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

MarshalJSON implements json.Marshaler

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) UnmarshalJSON added in v0.0.6

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

UnmarshalJSON implements json.Unmarshaler

Jump to

Keyboard shortcuts

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