plain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBFormat   = "plain"
	DBExt      = ".txt"
	MetaPrefix = "# Meta: "
	FieldSep   = ","
	FieldData  = "text"
)

Variables

This section is empty.

Functions

func Load added in v0.2.3

func Load(file string) (*model.Meta, *sdk.City, error)

Load opens the specified file, reads its contents, and initializes an IP database. The function first extracts meta information from the file, then parses the IP data, and finally creates an IP database based on the parsed data. FIXME: The plain database format reader has not been implemented yet, so I made a wrap in ipdb format.

Types

type Reader

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

Reader is a structure that provides functionalities to read from Plain Text.

func NewReader

func NewReader(file string) (*Reader, error)

NewReader initializes a new instance of Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the IP database.

func (*Reader) Find

func (r *Reader) Find(ip net.IP) (*model.IPInfo, error)

Find retrieves IP information based on the given IP address.

func (*Reader) Meta

func (r *Reader) Meta() *model.Meta

Meta returns the meta-information of the IP database.

func (*Reader) SetOption

func (r *Reader) SetOption(option interface{}) error

SetOption configures the Reader with the provided option.

type Writer

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

Writer provides functionalities to write IP data into plain text format.

func NewWriter

func NewWriter(meta *model.Meta) (*Writer, error)

NewWriter initializes a new Writer instance for writing IP data in plain text format. If the io.Writer is not nil, it will directly write data into it.

func (*Writer) Header

func (w *Writer) Header() error

Header writes the header information for the IP database.

func (*Writer) Insert

func (w *Writer) Insert(info *model.IPInfo) error

Insert adds the given IP information into the writer.

func (*Writer) SetOption

func (w *Writer) SetOption(option interface{}) error

SetOption sets the provided options to the Writer.

func (*Writer) WriteTo

func (w *Writer) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the buffered data into the provided writer.

type WriterOption

type WriterOption struct {
	// IW is for immediate output to the provided writer.
	IW io.Writer
}

WriterOption provides options for the Writer.

Jump to

Keyboard shortcuts

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