Documentation ¶
Index ¶
- Variables
- func ConvertValue(fieldName string, value string) interface{}
- func ExtractStrings(input []byte) (rest []byte, fields []string, err error)
- type Date
- func (d Date) AddDays(n int) Date
- func (d1 Date) After(d2 Date) bool
- func (d1 Date) Before(d2 Date) bool
- func (d Date) DaysSince(s Date) (days int)
- func (d Date) In(loc *time.Location) time.Time
- func (d Date) IsValid() bool
- func (d Date) IsZero() bool
- func (d Date) MarshalText() ([]byte, error)
- func (d Date) String() string
- func (d *Date) UnmarshalText(data []byte) error
- type DateTime
- func (dt1 DateTime) After(dt2 DateTime) bool
- func (dt1 DateTime) Before(dt2 DateTime) bool
- func (dt DateTime) In(loc *time.Location) time.Time
- func (dt DateTime) IsValid() bool
- func (dt DateTime) MarshalText() ([]byte, error)
- func (dt DateTime) String() string
- func (dt *DateTime) UnmarshalText(data []byte) error
- type FileHeader
- type FileParser
- type Kind
- type Line
- func (l *Line) Fields() (ret []interface{})
- func (l *Line) Get(key string) interface{}
- func (l *Line) GetAll() map[string]interface{}
- func (l *Line) GetAsString(key string) string
- func (l *Line) GetDate() (d Date)
- func (l *Line) GetTime() time.Time
- func (l *Line) MarshalJSON() ([]byte, error)
- func (l *Line) Names() (ret []string)
- func (l *Line) Reset(names []string)
- func (l *Line) WriteTo(w io.Writer, jsonExport bool) (err error)
- type Scanner
- type Time
Constants ¶
This section is empty.
Variables ¶
var ErrEndlineInsideQuotes = errors.New("Endline character appears in a quoted string")
ErrEndlineInsideQuotes is the error returned when the input shows an endline character inside a quoted string.
var ErrNoEndline = errors.New("No endline at end of input")
ErrNoEndline is the error returned by ExtractStrings when the input does not end with an endline character.
var ErrQuoteLeftOpen = errors.New("Unclosed quote in a W3C log line")
ErrQuoteLeftOpen is the error returned by ExtractStrings when the input shows an unclosed quoted string.
Functions ¶
func ConvertValue ¶
func ExtractStrings ¶
ExtractStrings scans the input for the next available log line. It returns the unparsed part of input in rest.
fields will contain the parsed fields of the log line.
err will be nil, ErrEndlineInsideQuotes, ErrNoEndline or ErrQuoteLeftOpen.
Types ¶
type Date ¶
type Date struct { Year int // Year (e.g., 2014). Month time.Month // Month of the year (January = 1, ...). Day int // Day of the month, starting at 1. }
A Date represents a date (year, month, day).
This type does not include location information, and therefore does not describe a unique 24-hour timespan.
func ParseDate ¶
ParseDate parses a string in RFC3339 full-date format and returns the date value it represents.
func (Date) AddDays ¶
AddDays returns the date that is n days in the future. n can also be negative to go into the past.
func (Date) DaysSince ¶
DaysSince returns the signed number of days between the date and s, not including the end day. This is the inverse operation to AddDays.
func (Date) In ¶
In returns the time corresponding to time 00:00:00 of the date in the location.
In is always consistent with time.Date, even when time.Date returns a time on a different day. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 0, 0, 0, loc)
and
civil.Date{Year: 1955, Month: time.May, Day: 1}.In(loc)
return 23:00:00 on April 30, 1955.
In panics if loc is nil.
func (Date) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of d.String().
func (*Date) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The date is expected to be a string in a format accepted by ParseDate.
type DateTime ¶
A DateTime represents a date and time.
This type does not include location information, and therefore does not describe a unique moment in time.
func DateTimeOf ¶
DateTimeOf returns the DateTime in which a time occurs in that time's location.
func ParseDateTime ¶
ParseDateTime parses a string and returns the DateTime it represents. ParseDateTime accepts a variant of the RFC3339 date-time format that omits the time offset but includes an optional fractional time, as described in ParseTime. Informally, the accepted format is
YYYY-MM-DDTHH:MM:SS[.FFFFFFFFF]
where the 'T' may be a lower-case 't'.
func (DateTime) In ¶
In returns the time corresponding to the DateTime in the given location.
If the time is missing or ambigous at the location, In returns the same result as time.Date. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 30, 0, 0, loc)
and
civil.DateTime{ civil.Date{Year: 1955, Month: time.May, Day: 1}}, civil.Time{Minute: 30}}.In(loc)
return 23:30:00 on April 30, 1955.
In panics if loc is nil.
func (DateTime) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of dt.String().
func (*DateTime) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The datetime is expected to be a string in a format accepted by ParseDateTime
type FileHeader ¶
type FileHeader struct { Software string Remark string Meta map[string]string // contains filtered or unexported fields }
FileHeader represents the header of a W3C Extended Log Format file.
func (*FileHeader) FieldNames ¶
func (h *FileHeader) FieldNames() (ret []string)
FieldNames returns a copy of the field names
func (*FileHeader) HasField ¶
func (h *FileHeader) HasField(name string) bool
func (*FileHeader) HasGmtTime ¶
func (h *FileHeader) HasGmtTime() bool
type FileParser ¶
type FileParser struct { FileHeader // contains filtered or unexported fields }
FileParser is used to parse a W3C Extended Log Format file.
func NewFileParser ¶
func NewFileParser(reader io.Reader) *FileParser
NewFileParser constructs a FileParser
func (*FileParser) Next ¶
func (p *FileParser) Next() (*Line, error)
Next returns the next parsed log line.
func (*FileParser) NextTo ¶
func (p *FileParser) NextTo(l *Line) (*Line, error)
NextTo returns the next parsed log line, reusing the given line.
func (*FileParser) ParseHeader ¶
func (p *FileParser) ParseHeader() error
ParseHeader is used to parse the header part of a W3C Extended Log Format file. The io.Reader should be at the start of the file.
func (*FileParser) SetFieldNames ¶
func (p *FileParser) SetFieldNames(fieldNames []string) *FileParser
SetFieldNames can be used to set the Field names manually, instead of parsing the header file.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line represents a parsed log line
func (*Line) GetAsString ¶
func (*Line) GetTime ¶
GetTime returns the log line timestamp. It returns the time.Time zero value if the timestamp can not be found.
func (*Line) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is a stream oriented parser for W3C Extended Log Format lines.
func (*Scanner) Scan ¶
Scan advances the Scanner to the next log line, which will then be available through the Strings method. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil.
type Time ¶
type Time struct { Hour int // The hour of the day in 24-hour format; range [0-23] Minute int // The minute of the hour; range [0-59] Second int // The second of the minute; range [0-59] Nanosecond int // The nanosecond of the second; range [0-999999999] }
A Time represents a time with nanosecond precision.
This type does not include location information, and therefore does not describe a unique moment in time.
This type exists to represent the TIME type in storage-based APIs like BigQuery. Most operations on Times are unlikely to be meaningful. Prefer the DateTime type.
func ParseTime ¶
ParseTime parses a string and returns the time value it represents. ParseTime accepts an extended form of the RFC3339 partial-time format. After the HH:MM:SS part of the string, an optional fractional part may appear, consisting of a decimal point followed by one to nine decimal digits. (RFC3339 admits only one digit after the decimal point).
func TimeOf ¶
TimeOf returns the Time representing the time of day in which a time occurs in that time's location. It ignores the date.
func (Time) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The output is the result of t.String().
func (Time) String ¶
String returns the date in the format described in ParseTime. If Nanoseconds is zero, no fractional part will be generated. Otherwise, the result will end with a fractional part consisting of a decimal point and nine digits.
func (*Time) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The time is expected to be a string in a format accepted by ParseTime.