dm_1

package
v0.0.0-...-a1b16c7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 21 Imported by: 0

README

dm_1

dm_1包中的所有类不应该对数据库和用户暴露,只能作为功能性调用。

ADD

go get github.com/nfnt/resize golang.org/x/sys/.. github.com/fsnotify/fsnotify github.com/gorilla/websocket

Documentation

Overview

进行一些基本的文件操作 参考: https://colobu.com/2016/10/12/go-file-operations/

进行log封装,用于对cc log进行区分

进行归档时候的操作

Index

Constants

This section is empty.

Variables

View Source
var (
	// http 请求-读写
	// websocket 只读
	TaskSharedList        DMTaskStatusList
	ForableTaskSharedList DMForableTaskSharedList
)
View Source
var (
	DMExts = map[string][]string{
		"image": []string{
			".png", ".jpeg", ".jpg", ".gif", ".bmp", ".psd", ".ai",
			".eps", ".tif", ".tiff", ".webp", ".raw", ".svg", ".svgz",
		},
		"video": []string{
			".flv", ".mp4", ".mov", ".wmv", ".avi", ".flv", ".mkv", ".swf",
		},
		"music": []string{
			".mp3", ".flac", ".wav", ".ape",
		},
		"backup": []string{
			".rar", ".zip", ".tar", ".bk", ".backup",
		},
		"document": []string{
			".doc", ".docx", ".pdf", ".ppt", ".pptx", ".xls", ".xlsx",
			".xla", ".md", ".txt", ".text",
		},
	}
)

Functions

func DMImageDecode

func DMImageDecode(ext string, f *os.File) (img image.Image, e error)

func DMImageEncode

func DMImageEncode(ext string, img image.Image) (buf *bytes.Buffer, e error)

有损格式均为默认选项

func DMRootPath

func DMRootPath() string

方便获取根目录路径

func Fail

func Fail(val ...interface{})

func Fatal

func Fatal(val ...interface{})

func Info

func Info(val ...interface{})

func Success

func Success(val ...interface{})

Types

type DMFileInfo

type DMFileInfo struct {
	Name    string      // base name of the file
	Size    int64       // length in bytes for regular files; system-dependent for others
	Mode    os.FileMode // file mode bits
	ModTime time.Time   // modification time
	IsDir   bool        // abbreviation for Mode().IsDire()
	Sys     interface{} // underlying data source (can return nil)
}

详见os包中的 types.go 用于方便转化为json对象

type DMFileInfoViewModel

type DMFileInfoViewModel struct {
	Name    string
	Size    int64
	Mode    string
	ModTime string
	IsDir   bool
	Sys     interface{}
}

详见os包中的 types.go 用于方便转化为json对象

type DMForableTaskSharedList

type DMForableTaskSharedList struct {
	Name string
	List []DMTaskStatus
}

type DMImage

type DMImage struct {
	DMResource
}

func (DMImage) IsValid

func (R DMImage) IsValid() bool

检查是否为图片文件

func (DMImage) Open

func (R DMImage) Open() (If DMImageFile, e error)

type DMImageFile

type DMImageFile struct {
	Image image.Image
	Ext   string
}

func (DMImageFile) Resize

func (R DMImageFile) Resize(maxW, maxH uint) DMImageFile

func (DMImageFile) ToBase64

func (R DMImageFile) ToBase64() (b64 string, er error)

type DMNotifyFile

type DMNotifyFile struct {
	Watch                                *fsnotify.Watcher
	Create, Write, Remove, Rename, Chmod DMWatchEventFunc
}

func DMNewNotifyFileEmpty

func DMNewNotifyFileEmpty() *DMNotifyFile

func (*DMNotifyFile) AddWatchDirRecruit

func (pR *DMNotifyFile) AddWatchDirRecruit(dir string) (e error)

递归监控目录 dir

func (*DMNotifyFile) RemoveWatchDirRecruit

func (pR *DMNotifyFile) RemoveWatchDirRecruit(dir string) (e error)

func (*DMNotifyFile) WatchEvent

func (pR *DMNotifyFile) WatchEvent()

type DMResource

type DMResource struct {
	DMFileInfo
	// 一个资源的绝对路径
	Path string
}

func DMRecruitLs

func DMRecruitLs(r DMResource, taskStatus *DMTaskStatus) (rs []DMResource)

递归某个目录的所有文件 结果不包含 r 自身 不会递归二进制文件夹,见 IsBinaryDirectory1()

func (DMResource) Exists

func (R DMResource) Exists() bool

func (*DMResource) GetBasicFileInfo

func (pR *DMResource) GetBasicFileInfo() (dfi *DMFileInfo, e error)

获取文件的基本信息

func (DMResource) GetExt

func (R DMResource) GetExt() (ext string, e error)

获取文件扩展名 返回形如 ".ext" e != nil 时表明路径非法或为一个目录

func (DMResource) GetGenre

func (R DMResource) GetGenre() string

dm_1.DMExts

func (DMResource) GetMD5

func (R DMResource) GetMD5() (md5str string, e error)

获取某个文件的md5 路径直接返回空字符串

func (DMResource) GetMD5Mask

func (R DMResource) GetMD5Mask() (md5str string, e error)

将MD5运算暂时保存

func (DMResource) GetSize

func (R DMResource) GetSize() (int64, error)

获取文件或文件夹的大小 与属性Size不同,当接收者为路径时GetSize可以返回文件夹的递归大小

func (DMResource) IsBinaryDirectory1

func (R DMResource) IsBinaryDirectory1() bool

如果目录下有exe文件,说明这个目录为二进制软件的目录 判断方式1

func (DMResource) IsDire

func (R DMResource) IsDire() bool

与IsDir区分

func (DMResource) IsFile

func (R DMResource) IsFile() bool

func (DMResource) Ls

func (R DMResource) Ls() (rs []DMResource, e error)

枚举所有的子文件夹 ls会自动调用所有子资源的GetBasicFileInfo进行填充

func (DMResource) LsLimited

func (R DMResource) LsLimited(head, end int) (totalCount int, rs []DMResource, e error)

枚举所有的子文件夹 ls会自动调用所有子资源的GetBasicFileInfo进行填充

func (DMResource) LsRecruit

func (R DMResource) LsRecruit(status *DMTaskStatus) []DMResource

包含 R 自身

func (DMResource) LsRecruitCount

func (R DMResource) LsRecruitCount() int

递归全部的子项目个数

func (DMResource) ToReadable

func (R DMResource) ToReadable() *DMFileInfoViewModel

type DMTaskStatus

type DMTaskStatus struct {
	TaskName string
	IsUni    bool

	Progress      int
	ProgressMax   int
	ProgressStage string

	IsFinished, Pause bool
	StartTime         time.Time
	TimeoutSec        float64
	CurrentMsg        string  // 当前工作的信息
	Errors            []error // bad design

	Terminal         bool
	SpanIntervalMSec int64 // 自旋时间间隔
}

func (*DMTaskStatus) Abort

func (pR *DMTaskStatus) Abort(e error)

func (*DMTaskStatus) Error

func (pR *DMTaskStatus) Error(e error)

func (*DMTaskStatus) Finished

func (pR *DMTaskStatus) Finished()

func (DMTaskStatus) IsTimeout

func (R DMTaskStatus) IsTimeout() bool

func (*DMTaskStatus) Msg

func (pR *DMTaskStatus) Msg(msg string)

func (*DMTaskStatus) MsgStage

func (pR *DMTaskStatus) MsgStage(msg string)

func (*DMTaskStatus) TryLock

func (R *DMTaskStatus) TryLock()

自旋,直至Pause == false

func (DMTaskStatus) UsedTime

func (R DMTaskStatus) UsedTime() time.Duration

type DMTaskStatusList

type DMTaskStatusList struct {
	Lists  map[string][]DMTaskStatus
	Errors []error
}

func (*DMTaskStatusList) AddTask

func (pR *DMTaskStatusList) AddTask(taskName string, isUni bool, timeout float64, progressMax int, SpanIntervalMSec int64) error

尝试创建一个unique的任务时返回错误

func (DMTaskStatusList) ToForable

func (R DMTaskStatusList) ToForable() (fs []DMForableTaskSharedList)

type DMWatchEventFunc

type DMWatchEventFunc func(event fsnotify.Event)

Jump to

Keyboard shortcuts

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