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