mayhem-party/src/device/input/raw/raw.go

27 lines
474 B
Go

package raw
import (
"context"
"os"
"strconv"
)
type Raw interface {
Read() []byte
Close()
}
func New(ctx context.Context) Raw {
if os.Getenv("RAW_KEYBOARD") == "true" {
return NewKeyboard()
}
if port, _ := strconv.Atoi(os.Getenv("RAW_UDP")); port != 0 {
return NewUDP(ctx, port)
}
generator := randomCharFromRange('a', 'g')
if p := os.Getenv("RAW_RANDOM_WEIGHT_FILE"); p != "" {
generator = randomCharFromWeightFile(p)
}
return NewRandom(generator)
}