/gozin

Dynamic select for golang

Primary LanguageGoMIT LicenseMIT

Gozin - Golang dynamic select

Build Status Coverage Status GoDoc Go Report Card

Gozin is a thin wrapper around the reflection api for select to create dynamic select at runtime.

func main() {
	t1 := make(chan int)
	t2 := make(chan int)
	close(t1)
	err := Select(
		Default(func() {
			fmt.Println("Default")
		}), Send(t2, 111, func() {
			fmt.Println("Send")
		}), Receive(t1, func(data interface{}, ok bool) {
			fmt.Println("Rec", data, ok)
		}))

	if err != nil {
		panic(err)
	}

	// Output: Rec 0 false
}

In Persian Gozin (گزین) means chosen.