storeFields stores fields for a result into individual files based on name.
(output *Result, storeFields []string)
| 61 | // storeFields stores fields for a result into individual files |
| 62 | // based on name. |
| 63 | func storeFields(output *Result, storeFields []string) { |
| 64 | parsed, err := urlutil.Parse(output.Request.URL) |
| 65 | if err != nil { |
| 66 | gologger.Warning().Msgf("storeFields: failed to parse url %v got %v", output.Request.URL, err) |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | hostname := parsed.Hostname() |
| 71 | etld, _ := publicsuffix.EffectiveTLDPlusOne(hostname) |
| 72 | rootURL := fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host) |
| 73 | for _, field := range storeFields { |
| 74 | if result := getValueForField(output, parsed.URL, hostname, etld, rootURL, field); result != "" { |
| 75 | appendToFileField(parsed.URL, field, result) |
| 76 | } |
| 77 | if _, ok := CustomFieldsMap[field]; ok { |
| 78 | results := getValueForCustomField(output) |
| 79 | for _, result := range results { |
| 80 | appendToFileField(parsed.URL, result.field, result.value) |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func appendToFileField(parsed *url.URL, field, data string) { |
| 87 | file, err := os.OpenFile(path.Join(storeFieldDir, fmt.Sprintf("%s_%s_%s.txt", parsed.Scheme, parsed.Hostname(), field)), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) |
no test coverage detected