nginx

package
v0.0.0-...-0f6f946 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2014 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(records []Record, url string) (total int64)

Count will count the number of records that include the given URL.

Types

type Date

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

Date is a simple year, month, and day representation. Go's "time" package has only a datetime representation (which could be truncated to serve as a date) and I desired a simple implementation.

func DateFromTime

func DateFromTime(t time.Time) Date

DateFromTime constructs a date from a time

func (Date) String

func (d Date) String() string

func (Date) ToTime

func (d Date) ToTime() time.Time

ToTime returns a UTC zoned time for this date

type DateCount

type DateCount struct {
	Date  Date
	Count int64
}

DateCount merely contains a date and count.

func CountDays

func CountDays(records []Record, url string, loc *time.Location) (int64, []DateCount)

CountDays will count the number of records that include the given URL and separate them by day in the given timezone.

type DateCounter

type DateCounter map[Date]int64

DateCounter is used to count views for a given date.

func (DateCounter) Range

func (dc DateCounter) Range() (counts []DateCount)

Range returns the ordered dates in the date counter, including any missing dates.

type Dates

type Dates []Date

Dates implements the sort.Sort interface. By default it will sort dates in ascending order.

func (Dates) Len

func (d Dates) Len() int

func (Dates) Less

func (d Dates) Less(i, j int) bool

func (Dates) Swap

func (d Dates) Swap(i, j int)

type Logs

type Logs struct {
	Files         int
	Plain, Zipped []string
}

func ReadDirectory

func ReadDirectory(dir string) (logs Logs, err error)

type Record

type Record struct {
	IP        string
	User      string // index 2
	Timestamp time.Time
	Request   string
	Method    string
	URL       string
	Version   string
	Status    int
	Bytes     int
	Referer   string
	Agent     string // index 8
}

The default configuration for nginx access logs: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" Skip index 1, it's just a dash

func OpenAndParseFile

func OpenAndParseFile(path string) (records []Record, err error)

func OpenAndParseZipFile

func OpenAndParseZipFile(path string) (records []Record, err error)

func ParseFile

func ParseFile(f io.ReadCloser) (records []Record, err error)

func ParseRow

func ParseRow(row []string) (r Record, err error)

func (Record) String

func (r Record) String() string

String rebuilds the Record into the default nginx log format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL