33 lines
684 B
Go
33 lines
684 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type ErrorResponse struct {
|
||
|
ErrorCode string `json:"errcode,omitempty"`
|
||
|
ErrorMessage string `json:"error,omitempty"`
|
||
|
RetryTime int `json:"retry_after_ms,omitempty"`
|
||
|
}
|
||
|
|
||
|
func CheckRequest(r *http.Request, request interface{}) (response *ErrorResponse) {
|
||
|
if !strings.Contains(r.Header.Get("Content-Type"), "application/json") {
|
||
|
response = &ErrorResponse{ErrorMessage: "Content Type not JSON"}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func IsJSONString(s string) bool {
|
||
|
var js string
|
||
|
return json.Unmarshal([]byte(s), &js) == nil
|
||
|
|
||
|
}
|
||
|
|
||
|
func IsJSON(s string) bool {
|
||
|
var js interface{}
|
||
|
return json.Unmarshal([]byte(s), &js) == nil
|
||
|
|
||
|
}
|