github.com/anishathalye/periscope@v0.3.5/internal/periscope/parameter.go (about)

     1  package periscope
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  var scanThreads = envGetInt("PERISCOPE_SCAN_THREADS", 32)
    10  var testDebug = envGetBool("PERISCOPE_TEST_DEBUG", false)
    11  
    12  func envGetInt(key string, fallback int) int {
    13  	if value, ok := os.LookupEnv(key); ok {
    14  		if i, err := strconv.ParseInt(value, 10, 0); err == nil {
    15  			return int(i)
    16  		}
    17  	}
    18  	return fallback
    19  }
    20  
    21  var stringToBool map[string]bool = map[string]bool{
    22  	"1":     true,
    23  	"t":     true,
    24  	"true":  true,
    25  	"y":     true,
    26  	"yes":   true,
    27  	"0":     false,
    28  	"f":     false,
    29  	"false": false,
    30  	"n":     false,
    31  	"no":    false,
    32  }
    33  
    34  func envGetBool(key string, fallback bool) bool {
    35  	if value, ok := os.LookupEnv(key); ok {
    36  		if b, ok := stringToBool[strings.ToLower(value)]; ok {
    37  			return b
    38  		}
    39  	}
    40  	return fallback
    41  }