72 lines
1.3 KiB
Plaintext
72 lines
1.3 KiB
Plaintext
|
|
package resultStatus
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
)
|
||
|
|
|
||
|
|
type StatusCode int
|
||
|
|
|
||
|
|
// ResultStatus
|
||
|
|
// @description: 状态码数据
|
||
|
|
type ResultStatus struct {
|
||
|
|
// 状态码
|
||
|
|
code StatusCode
|
||
|
|
|
||
|
|
// 消息
|
||
|
|
message string
|
||
|
|
}
|
||
|
|
|
||
|
|
// Code
|
||
|
|
// @description: 状态码
|
||
|
|
// parameter:
|
||
|
|
// @receiver this: this
|
||
|
|
// return:
|
||
|
|
// @StatusCode: 状态码
|
||
|
|
func (this *ResultStatus) Code() StatusCode {
|
||
|
|
return this.code
|
||
|
|
}
|
||
|
|
|
||
|
|
// Message
|
||
|
|
// @description: 错误信息
|
||
|
|
// parameter:
|
||
|
|
// @receiver this: this
|
||
|
|
// return:
|
||
|
|
// @string:
|
||
|
|
func (this *ResultStatus) Message() string {
|
||
|
|
return this.message
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewResultStatus
|
||
|
|
// @description: 创建新的状态码对象
|
||
|
|
// parameter:
|
||
|
|
// @_code: 错误码
|
||
|
|
// @_message: 提示消息
|
||
|
|
// return:
|
||
|
|
// @ResultStatus: 状态码对象
|
||
|
|
func NewResultStatus(_code StatusCode, _message string) ResultStatus {
|
||
|
|
return ResultStatus{
|
||
|
|
code: _code,
|
||
|
|
message: _message,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// IsSuccess
|
||
|
|
// @description: 是否是成功
|
||
|
|
// parameter:
|
||
|
|
// @receiver this: this
|
||
|
|
// return:
|
||
|
|
// @bool: true:成功 false:失败
|
||
|
|
func (this *ResultStatus) IsSuccess() bool {
|
||
|
|
return this.code == Success.Code()
|
||
|
|
}
|
||
|
|
|
||
|
|
// String
|
||
|
|
// @description: 打印状态码信息
|
||
|
|
// parameter:
|
||
|
|
// @receiver this: this
|
||
|
|
// return:
|
||
|
|
// @string: 状态码信息
|
||
|
|
func (this *ResultStatus) String() string {
|
||
|
|
return fmt.Sprintf("Code:%d,Message:%s", this.code, this.message)
|
||
|
|
}
|