-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Bottos-project/bottos
- Loading branch information
Showing
6 changed files
with
273 additions
and
101 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,18 @@ | ||
[{ | ||
"code": 1001, | ||
"lv": "ERROR", | ||
"msg": { | ||
"en": "username over length", | ||
"cn": "用户名过长" | ||
}, | ||
"details": "over length" | ||
},{ | ||
"code": 1002, | ||
"lv": "ERROR", | ||
"msg": { | ||
"en": "input tooshor", | ||
"cn": "密码太短" | ||
}, | ||
"details": "input tooshort" | ||
} | ||
] |
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,68 @@ | ||
// Copyright 2017~2022 The Bottos Authors | ||
// This file is part of the Bottos Chain library. | ||
// Created by Rocket Core Team of Bottos. | ||
|
||
//This program is free software: you can distribute it and/or modify | ||
//it under the terms of the GNU General Public License as published by | ||
//the Free Software Foundation, either version 3 of the License, or | ||
//(at your option) any later version. | ||
|
||
//This program is distributed in the hope that it will be useful, | ||
//but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
//GNU General Public License for more details. | ||
|
||
//You should have received a copy of the GNU General Public License | ||
// along with bottos. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/* | ||
* file description: provide a interface error definition for all modules | ||
* @Author: zl | ||
* @Date: 2018-4-25 | ||
* @Last Modified by: | ||
* @Last Modified time: | ||
*/ | ||
package error | ||
|
||
import ( | ||
"io/ioutil" | ||
"encoding/json" | ||
) | ||
|
||
type ErrorCode struct { | ||
Code int64 `json:"code"` | ||
Lv string `json:"lv"` | ||
Msg struct { | ||
Cn string `json:"cn"` | ||
En string `json:"en"` | ||
} `json:"msg"` | ||
Details string `json:"details"` | ||
} | ||
|
||
|
||
func GetErrorInfo(code int64) ErrorCode { | ||
d := GetAllErrorInfos() | ||
|
||
for _, v := range d { | ||
if code == v.Code { | ||
return v | ||
} | ||
} | ||
return ErrorCode{} | ||
} | ||
|
||
func GetAllErrorInfos() []ErrorCode { | ||
fr, err := ioutil.ReadFile("./ErrorCode.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var d []ErrorCode | ||
err = json.Unmarshal(fr, &d) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return d | ||
} | ||
|
||
|
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,11 @@ | ||
package error | ||
|
||
import "testing" | ||
|
||
func Test_getErrorInfo(t *testing.T) { | ||
t.Log(GetErrorInfo(1001)) | ||
} | ||
|
||
func Test_GetAllErrorInfos(t *testing.T) { | ||
t.Log(GetAllErrorInfos()) | ||
} |
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.