input Getenvs to FlagXYZ

This commit is contained in:
bel
2023-03-25 10:58:13 -06:00
parent ae1e32391c
commit a1a12b1873
9 changed files with 45 additions and 20 deletions

View File

@@ -6,21 +6,27 @@ import (
"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 os.Getenv("RAW_KEYBOARD") == "true" {
if FlagRawKeyboard {
return NewKeyboard()
}
if port, _ := strconv.Atoi(os.Getenv("RAW_UDP")); port != 0 {
if port, _ := strconv.Atoi(FlagRawUDP); port != 0 {
return NewUDP(ctx, port)
}
generator := randomCharFromRange('a', 'g')
if p := os.Getenv("RAW_RANDOM_WEIGHT_FILE"); p != "" {
generator = randomCharFromWeightFile(p)
if FlagRawRandomWeightFile != "" {
generator = randomCharFromWeightFile(FlagRawRandomWeightFile)
}
return NewRandom(generator)
}