fs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 21 Imported by: 3

Documentation

Overview

inspiring from https://www.youtube.com/watch?v=1B71SL6Y0kA

Index

Constants

View Source
const PathSeparator = string(os.PathSeparator)

Variables

View Source
var FileTypeMap = map[string]FileType{
	".txt": Txt,
	".doc": Doc,
}

Functions

func CheckExist

func CheckExist(src string) bool

func CheckImage

func CheckImage(src string) error

func CheckImageExt

func CheckImageExt(fileName string, uploadAllowExt []string) bool

func CheckImageSize

func CheckImageSize(f multipart.File, uploadMaxSize int) bool

func CheckNotExist

func CheckNotExist(src string) bool

func CheckPermission

func CheckPermission(src string) bool

func Copy

func Copy(filepath string, reader io.Reader) error

func CopyDir

func CopyDir(src, dst string) error

func CopyFile

func CopyFile(src, dst string) error

CopyFile : General Approach

func Create

func Create(filepath string) (*os.File, error)

func CreateDir

func CreateDir(filepath string) error

func DirClean

func DirClean(dir string) string

func FileNameClean

func FileNameClean(filename string) string

func FileNameEdit

func FileNameEdit(filename string) string

windows需要,由于linux的文件也要放到windows看,统一处理

func FindFile

func FindFile(path string) (string, error)

path和filepath两个包,filepath文件专用

func FindFiles

func FindFiles(path string, deep int8, num int) ([]string, error)

func FindFiles2

func FindFiles2(path string, deep int8, num int) ([]string, error)

path和filepath两个包,filepath文件专用

func GetDir

func GetDir(path string) string

func GetExt

func GetExt(file *multipart.FileHeader) (string, error)

func GetFileCreateTime

func GetFileCreateTime(path string) int64

func GetImageFullPath

func GetImageFullPath(uploadPath, runtimeRootPath string) string

func GetImageFullUrl

func GetImageFullUrl(uploadPath, name string) string

func GetImageName

func GetImageName(name string) string

func GetLogFilePath

func GetLogFilePath(RuntimeRootPath, LogSavePath string) string

func GetMP4Duration

func GetMP4Duration(filepath string) (lengthOfTime uint32, err error)

GetMP4Duration 获取视频时长,以秒计

func GetSize

func GetSize(f multipart.File) int

func IsNotExistMkdir

func IsNotExistMkdir(src string) error

func LastFile

func LastFile(dir string) (os.FileInfo, map[string]os.FileInfo, error)

func Md5

func Md5(path string) (string, error)

func Mkdir

func Mkdir(src string) error

func MkdirAll

func MkdirAll(src string) error

func MustOpen

func MustOpen(fileName, filePath string) (*os.File, error)

func NotExist

func NotExist(filepath string) bool

func OpenLogFile

func OpenLogFile(fileName, filePath string) (*os.File, error)

func PathClean

func PathClean(dir string) string

func RangeDir

func RangeDir(dir string, callback func(dir string, entry os.DirEntry) error) error

func SafeCopyFile

func SafeCopyFile(src, dst string) error

SafeCopyFile : Error handling by abstraction

func Split

func Split(path string) (dir, file string)

func Write

func Write(buf *bytes.Buffer, filename string) (n int, err error)

Types

type BoxHeader

type BoxHeader struct {
	Size       uint32
	FourccType [4]byte
	Size64     uint64
}

BoxHeader 信息头

type Dir

type Dir string

func (Dir) Open

func (d Dir) Open(name string) (*os.File, error)

type DirEntities

type DirEntities []os.DirEntry

func (DirEntities) Len

func (e DirEntities) Len() int

func (DirEntities) Less

func (e DirEntities) Less(i, j int) bool

func (DirEntities) Swap

func (e DirEntities) Swap(i, j int)

type File

type File struct {
	ID           uint64 `gorm:"primary_key" json:"id"`
	FileName     string `gorm:"type:varchar(100);not null" json:"file_name"`
	OriginalName string `gorm:"type:varchar(100);not null" json:"original_name"`
	URL          string `json:"url"`
	MD5          string `gorm:"type:varchar(32)" json:"md5"`
	Mime         string `json:"mime"`
	Size         uint64 `json:"size"`
}

type FileType

type FileType int
const (
	Unknown FileType = iota
	Txt
	Doc
	Docx
	Xls
	Xlsx
)

type SafeCopy

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

func (*SafeCopy) Close

func (c *SafeCopy) Close()

func (*SafeCopy) Copy

func (c *SafeCopy) Copy()

func (*SafeCopy) Create

func (c *SafeCopy) Create(dst string)

Directories

Path Synopsis
watch

Jump to

Keyboard shortcuts

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