readURLsFromInput checks if the input is a file path containing URLs. If it is, returns all URLs from the file. Otherwise returns the input as a single URL.
(input string)
| 191 | // readURLsFromInput checks if the input is a file path containing URLs. |
| 192 | // If it is, returns all URLs from the file. Otherwise returns the input as a single URL. |
| 193 | func readURLsFromInput(input string) []string { |
| 194 | // If input looks like a URL (has scheme), treat it as a single URL |
| 195 | if strings.HasPrefix(input, "http://") || strings.HasPrefix(input, "https://") { |
| 196 | return []string{input} |
| 197 | } |
| 198 | |
| 199 | // Try to open as a file |
| 200 | file, err := os.Open(input) |
| 201 | if err != nil { |
| 202 | // Not a file, treat as a URL |
| 203 | return []string{input} |
| 204 | } |
| 205 | defer file.Close() |
| 206 | |
| 207 | var urls []string |
| 208 | scanner := bufio.NewScanner(file) |
| 209 | for scanner.Scan() { |
| 210 | line := strings.TrimSpace(scanner.Text()) |
| 211 | if line == "" || strings.HasPrefix(line, "#") { |
| 212 | continue |
| 213 | } |
| 214 | urls = append(urls, line) |
| 215 | } |
| 216 | if err := scanner.Err(); err != nil { |
| 217 | log.Printf("[!] Error reading URL file: %v", err) |
| 218 | return []string{input} |
| 219 | } |
| 220 | |
| 221 | if len(urls) == 0 { |
| 222 | return []string{input} |
| 223 | } |
| 224 | |
| 225 | log.Printf("[*] Loaded %d URLs from %s", len(urls), input) |
| 226 | return urls |
| 227 | } |
| 228 | |
| 229 | // initConfig reads in config file and ENV variables if set. |
| 230 | func initConfig() { |
no outgoing calls