Created
August 17, 2016 12:22
-
-
Save gkbrk/536268ba8ddd796dca4fb2a4291c3157 to your computer and use it in GitHub Desktop.
Referer log parser
This file contains hidden or 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" | |
"fmt" | |
"os" | |
"log" | |
"strings" | |
"net/url" | |
) | |
func main() { | |
file, err := os.Open("/var/log/referer.log") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
for scanner.Scan() { | |
parts := strings.Split(scanner.Text(), " ") | |
page, err := url.Parse(parts[0]) | |
if err == nil { | |
ref, err := url.Parse(parts[1]) | |
if err == nil { | |
if ref.Host != "gkbrk.com" && ref.Host != "" { | |
if strings.Index(parts[0], "/2016") == 0 { | |
fmt.Printf("%s %s\n", page.Path, ref) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment