-
-
Save brettcannon/a2a37cc5aadbc91c02ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"flag" | |
"log" | |
"os" | |
"sort" | |
"strings" | |
) | |
func readFile(path string, values map[string]struct{}) error { | |
file, err := os.Open(path) | |
if err != nil { | |
return err | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
values[strings.ToLower(scanner.Text())] = struct{}{} | |
} | |
if err := scanner.Err(); err != nil { | |
return err | |
} | |
return nil | |
} | |
func writeFile(values map[string]struct{}, path string) error { | |
domains := make([]string, 0) | |
for d, _ := range values { | |
domains = append(domains, d) | |
} | |
sort.Strings(domains) | |
file, err := os.Create(path) | |
if err != nil { | |
return err | |
} | |
defer file.Close() | |
if _, err := file.WriteString(strings.Join(domains, "\n")); err != nil { | |
return err | |
} | |
return nil | |
} | |
func main() { | |
flag.Parse() | |
values := make(map[string]struct{}) | |
for _, path := range flag.Args() { | |
if err := readFile(path, values); err != nil { | |
log.Fatal(err) | |
} | |
} | |
if err := writeFile(values, "whitelist.txt"); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment