autofile

package module
v0.0.0-...-1c977f7 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

go-autofile

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoFile

type AutoFile struct {
	ID   string
	Path string
	// contains filtered or unexported fields
}

Automatically closes and re-opens file for writing. This is useful for using a log file with the logrotate tool.

func OpenAutoFile

func OpenAutoFile(path string) (af *AutoFile, err error)

func (*AutoFile) Close

func (af *AutoFile) Close() error

func (*AutoFile) Size

func (af *AutoFile) Size() (int64, error)

func (*AutoFile) Sync

func (af *AutoFile) Sync() error

func (*AutoFile) Write

func (af *AutoFile) Write(b []byte) (n int, err error)

type Group

type Group struct {
	BaseService

	ID   string
	Head *AutoFile // The head AutoFile to write to

	Dir string // Directory that contains .Head
	// contains filtered or unexported fields
}

func OpenGroup

func OpenGroup(headPath string) (g *Group, err error)

func (*Group) FindLast

func (g *Group) FindLast(prefix string) (match string, found bool, err error)

Searches backwards for the last line in Group with prefix. Scans each file forward until the end to find the last match.

func (*Group) Flush

func (g *Group) Flush() error

func (*Group) HeadSizeLimit

func (g *Group) HeadSizeLimit() int64

func (*Group) MaxIndex

func (g *Group) MaxIndex() int

func (*Group) NewReader

func (g *Group) NewReader(index int) (*GroupReader, error)

NOTE: if error, returns no GroupReader. CONTRACT: Caller must close the returned GroupReader

func (*Group) OnStart

func (g *Group) OnStart() error

func (*Group) OnStop

func (g *Group) OnStop()

NOTE: g.Head must be closed separately

func (*Group) ReadGroupInfo

func (g *Group) ReadGroupInfo() GroupInfo

Returns info after scanning all files in g.Head's dir

func (*Group) RotateFile

func (g *Group) RotateFile()

func (*Group) Search

func (g *Group) Search(prefix string, cmp SearchFunc) (*GroupReader, bool, error)

Searches for the right file in Group, then returns a GroupReader to start streaming lines. Returns true if an exact match was found, otherwise returns the next greater line that starts with prefix. CONTRACT: Caller must close the returned GroupReader

func (*Group) SetHeadSizeLimit

func (g *Group) SetHeadSizeLimit(limit int64)

func (*Group) SetTotalSizeLimit

func (g *Group) SetTotalSizeLimit(limit int64)

func (*Group) TotalSizeLimit

func (g *Group) TotalSizeLimit() int64

func (*Group) WriteLine

func (g *Group) WriteLine(line string) error

Auto appends "\n" NOTE: Writes are buffered so they don't write synchronously TODO: Make it halt if space is unavailable

type GroupInfo

type GroupInfo struct {
	MinIndex  int
	MaxIndex  int
	TotalSize int64
	HeadSize  int64
}

type GroupReader

type GroupReader struct {
	*Group
	// contains filtered or unexported fields
}

func (*GroupReader) Close

func (gr *GroupReader) Close() error

func (*GroupReader) CurIndex

func (gr *GroupReader) CurIndex() int

Cursor's file index.

func (*GroupReader) PushLine

func (gr *GroupReader) PushLine(line string)

func (*GroupReader) ReadLine

func (gr *GroupReader) ReadLine() (string, error)

Reads a line (without delimiter) just return io.EOF if no new lines found.

func (*GroupReader) SetIndex

func (gr *GroupReader) SetIndex(index int) error

type SearchFunc

type SearchFunc func(line string) (int, error)

Returns -1 if line comes after, 0 if found, 1 if line comes before.

func MakeSimpleSearchFunc

func MakeSimpleSearchFunc(prefix string, target int) SearchFunc

A simple SearchFunc that assumes that the marker is of form <prefix><number>. For example, if prefix is '#HEIGHT:', the markers of expected to be of the form:

#HEIGHT:1 ... #HEIGHT:2 ...

type SighupWatcher

type SighupWatcher struct {
	// contains filtered or unexported fields
}

Watchces for SIGHUP events and notifies registered AutoFiles

Jump to

Keyboard shortcuts

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