Refine some capital letters. Finish the Lock method.
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/tool/i18n"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type WebResult struct {
|
||||
@ -73,7 +74,13 @@ func FetchHttpStatus(code string) int {
|
||||
} else if code == SERVER.Code {
|
||||
return SERVER.HttpStatus
|
||||
} else {
|
||||
return UNKNOWN.HttpStatus
|
||||
//if this is an int. regard it as statusCode
|
||||
statusCode, err := strconv.Atoi(code)
|
||||
if err != nil {
|
||||
return UNKNOWN.HttpStatus
|
||||
} else {
|
||||
return statusCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +111,18 @@ func CustomWebResult(codeWrapper *CodeWrapper, description string) *WebResult {
|
||||
return wr
|
||||
}
|
||||
|
||||
//use standard http status code.
|
||||
func StatusCodeWebResult(statusCode int, description string) *WebResult {
|
||||
if description == "" {
|
||||
description = http.StatusText(statusCode)
|
||||
}
|
||||
wr := &WebResult{
|
||||
Code: fmt.Sprintf("%d", statusCode),
|
||||
Msg: description,
|
||||
}
|
||||
return wr
|
||||
}
|
||||
|
||||
func BadRequestI18n(request *http.Request, item *i18n.Item, v ...interface{}) *WebResult {
|
||||
return CustomWebResult(BAD_REQUEST, fmt.Sprintf(item.Message(request), v...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user