model

package
v1.2.1-0...-837fef5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuccessErrCode   = 200
	InnerSysErrCode  = 500
	BadParamErrCode  = 401
	BadReqCode       = 400
	UnknownErrorCode = 999
)
View Source
const IndexTypeMdict = "IndexTypeMdict"
View Source
const IndexTypeStardict = "IndexTypeMdict"

Variables

This section is empty.

Functions

func DecodeHex

func DecodeHex(str string) ([]byte, error)

func DecodeUTF16

func DecodeUTF16(b []byte) (string, error)

Types

type DictList

type DictList []*PlainDictionaryItem

func (DictList) Len

func (dlist DictList) Len() int

func (DictList) Less

func (dlist DictList) Less(i, j int) bool

func (DictList) Swap

func (dlist DictList) Swap(i, j int)

type DictType

type DictType string
const DictTypeMdict DictType = "Mdict"
const DictTypeStarDict DictType = "StarDict"

type DictionaryItem

type DictionaryItem struct {
	*PlainDictionaryItem
	MainDict GeneralDictionary
	PathInfo *DirItem
}

func (*DictionaryItem) ToPlain

func (dict *DictionaryItem) ToPlain() *PlainDictionaryItem

type DirDcitType

type DirDcitType string

type DirItem

type DirItem struct {
	BaseDir    string
	CurrentDir string

	IsValid bool

	DictType DictType

	// 特殊文件类型
	CoverImgPath string
	CoverImgType ImgType
	ConfigPath   string
	LicensePath  string

	// medict 文件路径
	MdictMdxFileName string
	MdictMdxAbsPath  string
	MdictMddAbsPath  []string

	// StartDict文件路径
	StarDictDzAbsPath  string
	StarDictAbsPath    string
	StarDictIdxAbsPath string
	StarDictIfoAbsPath string
}

DirItem 词典文件单元,以文件夹为基本单元,一个文件夹代表一个文件 词典类型优先级: 0: mdict: mdx/mdd 1: startdict: dz/ifo/idx 特殊文件 - .dtype 文件: 词典类型文件,可以是 _mdict.dtype 或是 _startdict.dtype 固定名称类型 - _cover.jpg 文件: 词典封面文件,仅支持 jpg 类型 - _dict.toml 文件: 当前词典配置文件,控制词典行为,暂未实现 - _dict.license 文件: 当前词典的授权文件, 通常为 GPL 授权

type GeneralDictionary

type GeneralDictionary interface {
	// 取得当前词典所有词列表
	KeyList() []string
	// BuildIndex 构建索引
	BuildIndex() error
	// DictType 返回词典类型, 目前仅支持 mdict 和 stardict
	DictType() DictType
	// Description 返回词典描述
	Description() *PlainDictionaryInfo
	// Name 返回词典名称(主要是为了解决mdict的外部资源问题)
	Name() string
	// Lookup 直接输入 keyword 遍历词典搜索
	Lookup(keyword string) ([]byte, error)
	// LookupResource 搜索词典资源,包括 css/js/图片/字体等, 仅限制支持在词典所在文件夹
	LookupResource(keyword string) ([]byte, error)
	// Locate 使用索引定位词条,并返回 html 释义
	Locate(entry *KeyQueryIndex) ([]byte, error)
	// Search 返回近似词条索引列表,用于后续 Locate
	Search(keyword string) ([]*KeyQueryIndex, error)
}

type ImgType

type ImgType string
const ImgTypeJPG ImgType = "jpg"
const ImgTypePNG ImgType = "png"

type KeyQueryIndex

type KeyQueryIndex struct {
	IndexType string `json:"index_type"`
	*MdictKeyWordIndex
}

type MdictKeyWordIndex

type MdictKeyWordIndex struct {
	ID                            int    `json:"id"`
	KeyWord                       string `json:"keyword"`
	RecordLocateStartOffset       int64  `json:"record_start_offset"`
	RecordLocateEndOffset         int64  `json:"record_end_offset"`
	IsUTF16                       int    `json:"is_utf16"`
	IsRecordEncrypt               int    `json:"is_record_encrypt"`
	IsMDD                         int    `json:"is_mdd"`
	RecordBlockDataStartOffset    int64  `json:"record_block_data_start_offset"`
	RecordBlockDataCompressSize   int64  `json:"record_block_data_compress_size"`
	RecordBlockDataDeCompressSize int64  `json:"record_block_data_decompress_size"`
	KeyWordDataStartOffset        int64  `json:"keyword_data_start_offset"`
	KeyWordDataEndOffset          int64  `json:"keyword_data_end_offset"`
}

type MdictMeta

type MdictMeta struct {
	ID               string
	Title            string
	Filepath         string
	Description      string
	IsRecordEncoding bool
	IsUTF16          bool
	IsMDD            bool
}

type PlainDictionaryInfo

type PlainDictionaryInfo struct {
	Title                 string `json:"title"`
	Description           string `json:"description"`
	CreateDate            string `json:"createDate"`
	GenerateEngineVersion string `json:"generateEngineVersion"`
}

type PlainDictionaryItem

type PlainDictionaryItem struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	DictDir string `json:"base_dir"`

	Background string `json:"background"`
	DictType   string `json:"dict_type"`

	Description *PlainDictionaryInfo `json:"description"`
}

type Resp

type Resp struct {
	Data interface{} `json:"data"`
	Err  string      `json:"err"`
	Code int         `json:"code"`
}

func BuildError

func BuildError(err error, code int) *Resp

func BuildRawError

func BuildRawError(err string, code int) *Resp

func BuildSuccess

func BuildSuccess(data interface{}) *Resp

Jump to

Keyboard shortcuts

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