This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from Starnop/const-code
refactor: extract the common const code to the common folder
- Loading branch information
Showing
12 changed files
with
145 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package constants | ||
|
||
// This file defines the code required for both dfget and supernode. | ||
|
||
var cmmap = make(map[int]string) | ||
|
||
func init() { | ||
cmmap[Success] = "success" | ||
|
||
cmmap[CodeSystemError] = "system error" | ||
cmmap[CodeParamError] = "param is illegal" | ||
cmmap[CodeTargetNotFound] = "target not found" | ||
|
||
cmmap[CodePeerFinish] = "peer task end" | ||
cmmap[CodePeerContinue] = "peer task go on" | ||
cmmap[CodePeerWait] = "peer task wait" | ||
cmmap[CodePeerLimited] = "peer down limit" | ||
cmmap[CodeSuperFail] = "super node sync source fail" | ||
cmmap[CodeUnknownError] = "unknown error" | ||
cmmap[CodeTaskConflict] = "task conflict" | ||
cmmap[CodeURLNotReachable] = "url is not reachable" | ||
cmmap[CodeNeedAuth] = "need auth" | ||
cmmap[CodeWaitAuth] = "wait auth" | ||
} | ||
|
||
// GetMsgByCode gets the description of the code. | ||
func GetMsgByCode(code int) string { | ||
if v, ok := cmmap[code]; ok { | ||
return v | ||
} | ||
return "" | ||
} | ||
|
||
const ( | ||
// HTTPError represents that there is an error between client and server. | ||
HTTPError = -100 | ||
) | ||
|
||
/* the response code returned by supernode */ | ||
const ( | ||
// Success represents the request is success. | ||
Success = 200 | ||
|
||
CodeSystemError = 500 | ||
CodeParamError = 501 | ||
CodeTargetNotFound = 502 | ||
|
||
CodePeerFinish = 600 | ||
CodePeerContinue = 601 | ||
CodePeerWait = 602 | ||
CodePeerLimited = 603 | ||
CodeSuperFail = 604 | ||
CodeUnknownError = 607 | ||
CodeTaskConflict = 608 | ||
CodeURLNotReachable = 609 | ||
CodeNeedAuth = 610 | ||
CodeWaitAuth = 611 | ||
CodeSourceError = 612 | ||
) | ||
|
||
/* the code of task result that dfget will report to supernode */ | ||
const ( | ||
ResultFail = 500 | ||
ResultSuc = 501 | ||
ResultInvalid = 502 | ||
// ResultSemiSuc represents the result is partial successful. | ||
ResultSemiSuc = 503 | ||
) | ||
|
||
/* the code of task status that dfget will report to supernode */ | ||
const ( | ||
TaskStatusStart = 700 | ||
TaskStatusRunning = 701 | ||
TaskStatusFinish = 702 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.