github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/requester/downloader/status.go (about) 1 package downloader 2 3 import ( 4 "github.com/fzfile/BaiduPCS-Go/requester/transfer" 5 ) 6 7 type ( 8 //WorkerStatuser 状态 9 WorkerStatuser interface { 10 StatusCode() StatusCode //状态码 11 StatusText() string 12 } 13 14 //StatusCode 状态码 15 StatusCode int 16 17 //WorkerStatus worker状态 18 WorkerStatus struct { 19 statusCode StatusCode 20 } 21 22 // DownloadStatusFunc 下载状态处理函数 23 DownloadStatusFunc func(status transfer.DownloadStatuser, workersCallback func(RangeWorkerFunc)) 24 ) 25 26 const ( 27 //StatusCodeInit 初始化 28 StatusCodeInit StatusCode = iota 29 //StatusCodeSuccessed 成功 30 StatusCodeSuccessed 31 //StatusCodePending 等待响应 32 StatusCodePending 33 //StatusCodeDownloading 下载中 34 StatusCodeDownloading 35 //StatusCodeWaitToWrite 等待写入数据 36 StatusCodeWaitToWrite 37 //StatusCodeInternalError 内部错误 38 StatusCodeInternalError 39 //StatusCodeTooManyConnections 连接数太多 40 StatusCodeTooManyConnections 41 //StatusCodeNetError 网络错误 42 StatusCodeNetError 43 //StatusCodeFailed 下载失败 44 StatusCodeFailed 45 //StatusCodePaused 已暂停 46 StatusCodePaused 47 //StatusCodeReseted 已重设连接 48 StatusCodeReseted 49 //StatusCodeCanceled 已取消 50 StatusCodeCanceled 51 ) 52 53 //GetStatusText 根据状态码获取状态信息 54 func GetStatusText(sc StatusCode) string { 55 switch sc { 56 case StatusCodeInit: 57 return "初始化" 58 case StatusCodeSuccessed: 59 return "成功" 60 case StatusCodePending: 61 return "等待响应" 62 case StatusCodeDownloading: 63 return "下载中" 64 case StatusCodeWaitToWrite: 65 return "等待写入数据" 66 case StatusCodeInternalError: 67 return "内部错误" 68 case StatusCodeTooManyConnections: 69 return "连接数太多" 70 case StatusCodeNetError: 71 return "网络错误" 72 case StatusCodeFailed: 73 return "下载失败" 74 case StatusCodePaused: 75 return "已暂停" 76 case StatusCodeReseted: 77 return "已重设连接" 78 case StatusCodeCanceled: 79 return "已取消" 80 default: 81 return "未知状态码" 82 } 83 } 84 85 //NewWorkerStatus 初始化WorkerStatus 86 func NewWorkerStatus() *WorkerStatus { 87 return &WorkerStatus{ 88 statusCode: StatusCodeInit, 89 } 90 } 91 92 //SetStatusCode 设置worker状态码 93 func (ws *WorkerStatus) SetStatusCode(sc StatusCode) { 94 ws.statusCode = sc 95 } 96 97 //StatusCode 返回状态码 98 func (ws *WorkerStatus) StatusCode() StatusCode { 99 return ws.statusCode 100 } 101 102 //StatusText 返回状态信息 103 func (ws *WorkerStatus) StatusText() string { 104 return GetStatusText(ws.statusCode) 105 }