diff options
author | Emile <hanemile@protonmail.com> | 2019-11-02 22:10:43 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-11-02 22:10:43 +0100 |
commit | c0421a84f25a81f1c02569ac73f2175c5018983c (patch) | |
tree | 568cddccac86f4a380c444f043e514ce2cdd8e6a | |
parent | 52d650d76d51974c5a893a1b620ec342d808f8e3 (diff) |
parse hide and show flags
-rw-r--r-- | src/flags.go | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/flags.go b/src/flags.go index bda7c30..3a3af88 100644 --- a/src/flags.go +++ b/src/flags.go @@ -2,7 +2,10 @@ package main import ( "flag" + "fmt" "log" + "strconv" + "strings" ) var ( @@ -26,6 +29,16 @@ var ( httpServerPort int // string values defining what request to show or hide + hideCode string + hideLine string + hideWord string + hideChar string + + showCode string + showLine string + showWord string + showChar string + hide Hide show Show ) @@ -89,9 +102,87 @@ func registerFlags() { flag.IntVar(&httpServerPort, "httpServerPort", 8080, httpServerPortUsage) flag.IntVar(&httpServerPort, "hsp", 8080, httpServerPortUsage+shortcut) + // hide / show + hideCodeUsage := "Status codes to hide, comma seperated" + flag.StringVar(&hideCode, "hideCode", "", hideCodeUsage) + flag.StringVar(&hideCode, "hc", "", hideCodeUsage+shortcut) + + hideLineUsage := "Response body with given amount of words to hide, comma seperated" + flag.StringVar(&hideLine, "hideLine", "", hideLineUsage) + flag.StringVar(&hideLine, "hl", "", hideLineUsage+shortcut) + + hideWordUsage := "Response body with given amount of words to hide, comma seperated" + flag.StringVar(&hideWord, "hideWord", "", hideWordUsage) + flag.StringVar(&hideWord, "hw", "", hideWordUsage+shortcut) + + hideCharUsage := "Response body with given amount of chars to hide, comma seperated" + flag.StringVar(&hideChar, "hideChar", "", hideCharUsage) + flag.StringVar(&hideChar, "hch", "", hideCharUsage+shortcut) + + showCodeUsage := "Status codes to show, comma seperated" + flag.StringVar(&showCode, "showCode", "", showCodeUsage) + flag.StringVar(&showCode, "sc", "", showCodeUsage+shortcut) + + showLineUsage := "Response body with given amount of words to show, comma seperated" + flag.StringVar(&showLine, "showLine", "", showLineUsage) + flag.StringVar(&showLine, "sl", "", showLineUsage+shortcut) + + showWordUsage := "Response body with given amount of words to show, comma seperated" + flag.StringVar(&showWord, "showWord", "", showWordUsage) + flag.StringVar(&showWord, "sw", "", showWordUsage+shortcut) + + showCharUsage := "Response body with given amount of chars to show, comma seperated" + flag.StringVar(&showChar, "showChar", "", showCharUsage) + flag.StringVar(&showChar, "sch", "", showCharUsage+shortcut) + // parse the flags flag.Parse() + hide = Hide{ + HideCode: parseIntList(hideCode), + HideLine: parseIntList(hideLine), + HideWord: parseIntList(hideWord), + HideChar: parseIntList(hideChar), + } + + show = Show{ + ShowCode: parseIntList(showCode), + ShowLine: parseIntList(showLine), + ShowWord: parseIntList(showWord), + ShowChar: parseIntList(showChar), + } + log.Printf("%s Done reading flags", boldGreen("[+]")) } + +// parseIntList parses the given string by spliting it at commas returning a list of all ints +func parseIntList(inputStringList string) []int { + + // if the input list is empty, return an empty list + if inputStringList == "" { + return []int{} + } + + // define an array to store the black or whitelisted values in + var intList []int + + // split the input + elementList := strings.Split(inputStringList, ",") + + // parse all elements inserting the into the intList + for _, element := range elementList { + rawInt, err := strconv.Atoi(element) + + if err != nil { + fmt.Println("Could not parse: %s", err) + } else { + intList = append(intList, rawInt) + } + } + + log.Println(intList) + + // return the intList + return intList +} |