32 lines
663 B
Go
32 lines
663 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) (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
|
|
|
|
}
|