util

package
v0.0.0-...-86d34a5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TASK_CREATE = "1010" //任务创建
	TASK_START  = "1020" //任务开始
	TASK_SROP   = "1030" //任务暂停
	TASK_UPDATE = "1040" //任务修改
	TASK_DELETE = "1050" //任务删除
	TASK_UNABLE = "1060" //无效任务
)
View Source
const (
	FILE_COPY = iota //文件复制
	FILE_CUT         //文件移动
)
View Source
const (
	TASK_IS_STOP    = iota //任务停止
	TASK_IS_RUNED          //任务完成
	TASK_IS_RUNNING        //任务运行中
)
View Source
const (
	TRAN_DIR  = iota //传输目录
	TRAN_FILE        //传输文件
)

Variables

View Source
var (
	MAX_MESSAGE_LEN   = 1024             //每次接收消息的最大长度(字节)
	MAX_FILE_DATA_LEN = 16 * 1024 * 1024 //每次接收文件数据的最大长度(字节)
)

Functions

func CheckIPIsLocalIP

func CheckIPIsLocalIP(ipaddr string) bool

Check IP is local ip address returns true or false

func CheckIsDirByPath

func CheckIsDirByPath(path string) bool

check path is dir returns true/false

func CreateSocketConnect

func CreateSocketConnect(ipAddr string, port int) (conn net.Conn, err error)

func CreateSocketListen

func CreateSocketListen(ipAddr string, port int) (tcpListen *net.TCPListener, err error)

func GetCurrentFileList

func GetCurrentFileList(filePath string) (filelist, filedir []string, err error)

Get current file list by file full path returns the file list or err

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the local ip address

func HashFile

func HashFile(filename string) (hash string, err error)

get file md5sum return hash or err

func MkdirAllByPath

func MkdirAllByPath(dirPath string) bool

Mkdir all by full path returns true/false

func RecvFile

func RecvFile(ctx context.Context, conn net.Conn, filename string, filesize uint64) (flag bool, err error)

func SendFile

func SendFile(ctx context.Context, conn net.Conn, filename string) (sendLen int64, err error)

func SetStructByJSON

func SetStructByJSON(obj interface{}, mapData map[string]interface{}) error

SetStructByJSON 由json对象生成 struct

Types

type FileInfo

type FileInfo struct {
	Name string `json:"name"`
	Size uint64 `json:"size"`
}

type RespMessage

type RespMessage struct {
	TaskType string
	Status   bool
}

func (*RespMessage) CheckRespIsTureOrFalse

func (this *RespMessage) CheckRespIsTureOrFalse(respJson []byte) bool

func (*RespMessage) GetRespMessageJson

func (this *RespMessage) GetRespMessageJson() string

Response json pack

type Semaphore

type Semaphore struct {
	TotalThreads chan struct{}
	SemWaitGroup sync.WaitGroup
}

func NewSemaphore

func NewSemaphore(TotalNums int) *Semaphore

func (*Semaphore) Close

func (sem *Semaphore) Close()

func (*Semaphore) P

func (sem *Semaphore) P()

func (*Semaphore) V

func (sem *Semaphore) V()

func (*Semaphore) Wait

func (sem *Semaphore) Wait()

Jump to

Keyboard shortcuts

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