Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Referer log parser
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
You can’t perform that action at this time.