Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DbSearcher ¶
type DbSearcher struct {
Version int64 // 版本
ClientID int64 // 客户端ID
// contains filtered or unexported fields
}
DbSearcher 提供在数据库中搜索数据的方法。 它支持三种类型的搜索算法:内存、二进制和B树。 数据库类型(IPv4或IPv6)和查询类型(MEMORY、BINARY、BTREE)在运行时确定。 该类还提供根据查询类型初始化搜索参数的方法,以及通过IP地址获取地区的方法。 DbSearcher类使用RandomAccessFile从数据库文件读取和写入。 对于B树搜索,它使用2D字节数组和整数数组来表示每个索引块的起始IP和数据指针。 对于内存和二进制搜索,它使用字节数组来表示数据库的原始二进制字符串。 该类还提供关闭数据库的方法。
func NewDbSearcher ¶
func NewDbSearcher(dbFile string, queryType string, key string) (*DbSearcher, error)
NewDbSearcher 创建一个新的DbSearcher实例 queryType: 内存:MEMORY 文件:BTREE
func (*DbSearcher) Close ¶
func (ds *DbSearcher) Close()
func (*DbSearcher) Search ¶
func (ds *DbSearcher) Search(ip string) (string, error)
Search
- 此方法用于根据提供的IP地址在数据库中搜索区域。
- 它支持三种类型的搜索算法:内存搜索、二分查找和B树搜索。
- 搜索算法的类型由DbSearcher实例的queryType属性决定。
- 该方法首先将IP地址转换为字节数组,然后根据查询类型执行搜索。
- 如果搜索成功,它将返回找到的数据块的区域信息。
- 如果搜索不成功,则返回null。 *
- @param ip 要搜索的IP地址。它是一个标准IP地址格式的字符串。
- @return 如果搜索成功,返回找到的数据块的区域信息;否则返回null。
- @throws IpFormatException 如果提供的IP地址格式不正确,则抛出此异常。
- @throws IOException 如果在搜索过程中发生I/O错误,则抛出此异常。
type Decryptor ¶
type Decryptor struct {
// contains filtered or unexported fields
}
func NewDecryptor ¶
type RandomAccessFile ¶
RandomAccessFile 结构体扩展了标准库的 os.File, 并为文件指针添加了一个偏移量。 每当调用 Seek1 方法时,都会添加这个偏移量。 这在您想将文件的一部分视为单独文件时很有用。
func NewRandomAccessFile ¶
func NewRandomAccessFile(name string, offset int64) (*RandomAccessFile, error)
NewRandomAccessFile 创建一个新的 RandomAccessFile 实例。 每当调用 Seek1 方法时,偏移量会被添加到文件指针上。
参数:
name: 系统依赖的文件名 flag: 打开文件的模式(例如 os.O_RDONLY, os.O_RDWR 等) perm: 文件权限(如果创建新文件) offset: 要添加到文件指针的偏移量
返回值:
*RandomAccessFile: 新创建的 RandomAccessFile 实例 error: 如果在打开或创建文件时发生错误
func (*RandomAccessFile) Length ¶
func (f *RandomAccessFile) Length() (int64, error)
Length 返回文件的大小,考虑了偏移量。
返回值:
int64: 文件大小(字节) error: 如果发生 I/O 错误
func (*RandomAccessFile) ReadFully ¶
func (f *RandomAccessFile) ReadFully(p []byte) error
func (*RandomAccessFile) ReadFullyAt ¶
func (f *RandomAccessFile) ReadFullyAt(p []byte, off, length int) error
func (*RandomAccessFile) Seek1 ¶
func (f *RandomAccessFile) Seek1(offset int64) (int64, error)
Seek1 设置下一次读取或写入操作的文件指针偏移量,从文件开头开始计算。 偏移量可以设置在文件末尾之后。设置超过文件末尾的偏移量不会改变文件长度。 文件长度只会通过在设置偏移量超过文件末尾后进行写入操作而改变。
参数:
offset: 要设置的偏移量,以字节为单位,从文件开头开始计算 whence: 偏移量的参考点(io.SeekStart, io.SeekCurrent, 或 io.SeekEnd)
返回值:
int64: 新的文件偏移量 error: 如果 offset 小于 0 或发生 I/O 错误