fix golint issues in rest (#529)
This commit is contained in:
@@ -60,6 +60,7 @@ func ParseForm(r *http.Request, v interface{}) error {
|
||||
return formUnmarshaler.Unmarshal(params, v)
|
||||
}
|
||||
|
||||
// ParseHeader parses the request header and returns a map.
|
||||
func ParseHeader(headerValue string) map[string]string {
|
||||
ret := make(map[string]string)
|
||||
fields := strings.Split(headerValue, separator)
|
||||
|
||||
@@ -13,6 +13,7 @@ var (
|
||||
lock sync.RWMutex
|
||||
)
|
||||
|
||||
// Error writes err into w.
|
||||
func Error(w http.ResponseWriter, err error) {
|
||||
lock.RLock()
|
||||
handler := errorHandler
|
||||
@@ -32,20 +33,24 @@ func Error(w http.ResponseWriter, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Ok writes HTTP 200 OK into w.
|
||||
func Ok(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
// OkJson writes v into w with 200 OK.
|
||||
func OkJson(w http.ResponseWriter, v interface{}) {
|
||||
WriteJson(w, http.StatusOK, v)
|
||||
}
|
||||
|
||||
// SetErrorHandler sets the error handler, which is called on calling Error.
|
||||
func SetErrorHandler(handler func(error) (int, interface{})) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
errorHandler = handler
|
||||
}
|
||||
|
||||
// WriteJson writes v as json string into w with code.
|
||||
func WriteJson(w http.ResponseWriter, code int, v interface{}) {
|
||||
w.Header().Set(ContentType, ApplicationJson)
|
||||
w.WriteHeader(code)
|
||||
|
||||
@@ -2,6 +2,7 @@ package httpx
|
||||
|
||||
import "net/http"
|
||||
|
||||
// Router interface represents a http router that handles http requests.
|
||||
type Router interface {
|
||||
http.Handler
|
||||
Handle(method string, path string, handler http.Handler) error
|
||||
|
||||
@@ -1,19 +1,31 @@
|
||||
package httpx
|
||||
|
||||
const (
|
||||
// ApplicationJson means application/json.
|
||||
ApplicationJson = "application/json"
|
||||
// ContentEncoding means Content-Encoding.
|
||||
ContentEncoding = "Content-Encoding"
|
||||
// ContentSecurity means X-Content-Security.
|
||||
ContentSecurity = "X-Content-Security"
|
||||
ContentType = "Content-Type"
|
||||
KeyField = "key"
|
||||
SecretField = "secret"
|
||||
TypeField = "type"
|
||||
CryptionType = 1
|
||||
// ContentType means Content-Type.
|
||||
ContentType = "Content-Type"
|
||||
// KeyField means key.
|
||||
KeyField = "key"
|
||||
// SecretField means secret.
|
||||
SecretField = "secret"
|
||||
// TypeField means type.
|
||||
TypeField = "type"
|
||||
// CryptionType means cryption.
|
||||
CryptionType = 1
|
||||
)
|
||||
|
||||
const (
|
||||
// CodeSignaturePass means signature verification passed.
|
||||
CodeSignaturePass = iota
|
||||
// CodeSignatureInvalidHeader means invalid header in signature.
|
||||
CodeSignatureInvalidHeader
|
||||
// CodeSignatureWrongTime means wrong timestamp in signature.
|
||||
CodeSignatureWrongTime
|
||||
// CodeSignatureInvalidToken means invalid token in signature.
|
||||
CodeSignatureInvalidToken
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user