Documentation ¶
Index ¶
- Constants
- func CollectEscapeStringOption(option string, input map[string]interface{}, collectors ...func(v string)) error
- func CollectStringOption(option string, input map[string]interface{}, collectors ...func(v string)) error
- func DeferClose(c io.Closer, err *error)
- func DoDelete(client *http.Client, url string) (int, error)
- func ErrorResp(rd *render.Render, w http.ResponseWriter, err error)
- func GetComponentNameOnHTTP(r *http.Request) string
- func GetIPAddrFromHTTPRequest(r *http.Request) string
- func GetJSON(client *http.Client, url string, data []byte) (*http.Response, error)
- func GetRouteName(req *http.Request) string
- func NewCustomReverseProxies(dialClient *http.Client, urls []url.URL) http.Handler
- func ParseKey(name string, input map[string]interface{}) ([]byte, string, error)
- func PatchJSON(client *http.Client, url string, data []byte) (*http.Response, error)
- func PostJSON(client *http.Client, url string, data []byte) (*http.Response, error)
- func PostJSONIgnoreResp(client *http.Client, url string, data []byte) error
- func ReadJSON(r io.ReadCloser, data interface{}) error
- func ReadJSONRespondError(rd *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error
- func RegisterUserDefinedHandlers(registerMap map[string]http.Handler, group *APIServiceGroup, ...) error
- func TagJSONError(err error) error
- type APIServiceGroup
- type AccessPath
- type ComponentSignatureRoundTripper
- type FieldError
- type JSONError
Constants ¶
const ( // ErrRedirectFailed is the error message for redirect failed. ErrRedirectFailed = "redirect failed" // ErrRedirectToNotLeader is the error message for redirect to not leader. ErrRedirectToNotLeader = "redirect to not leader" )
const ( // CorePath the core group, is at REST path `/pd/api/v1`. CorePath = "/pd/api/v1" // ExtensionsPath the named groups are REST at `/pd/apis/{GROUP_NAME}/{Version}`. ExtensionsPath = "/pd/apis" )
Variables ¶
This section is empty.
Functions ¶
func CollectEscapeStringOption ¶
func CollectEscapeStringOption(option string, input map[string]interface{}, collectors ...func(v string)) error
CollectEscapeStringOption is used to collect string using escaping from input map for given option
func CollectStringOption ¶
func CollectStringOption(option string, input map[string]interface{}, collectors ...func(v string)) error
CollectStringOption is used to collect string using from input map for given option
func DeferClose ¶
DeferClose captures the error returned from closing (if an error occurs). This is designed to be used in a defer statement.
func ErrorResp ¶
func ErrorResp(rd *render.Render, w http.ResponseWriter, err error)
ErrorResp Respond to the client about the given error, integrating with errcode.ErrorCode.
Important: if the `err` is just an error and not an errcode.ErrorCode (given by errors.Cause), then by default an error is assumed to be a 500 Internal Error.
If the error is nil, this also responds with a 500 and logs at the error level.
func GetComponentNameOnHTTP ¶
GetComponentNameOnHTTP returns component name from Request Header
func GetIPAddrFromHTTPRequest ¶
GetIPAddrFromHTTPRequest returns http client IP from context. Because `X-Forwarded-For ` header has been written into RFC 7239(Forwarded HTTP Extension), so `X-Forwarded-For` has the higher priority than `X-Real-IP`. And both of them have the higher priority than `RemoteAddr`
func GetRouteName ¶
GetRouteName return mux route name registered
func NewCustomReverseProxies ¶
NewCustomReverseProxies returns the custom reverse proxies.
func PostJSONIgnoreResp ¶
PostJSONIgnoreResp is used to do post request with JSON body and ignore response.
func ReadJSON ¶
func ReadJSON(r io.ReadCloser, data interface{}) error
ReadJSON reads a JSON data from r and then closes it. An error due to invalid json will be returned as a JSONError
func ReadJSONRespondError ¶
func ReadJSONRespondError(rd *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error
ReadJSONRespondError writes json into data. On error respond with a 400 Bad Request
func RegisterUserDefinedHandlers ¶
func RegisterUserDefinedHandlers(registerMap map[string]http.Handler, group *APIServiceGroup, handler http.Handler) error
RegisterUserDefinedHandlers register the user defined handlers.
func TagJSONError ¶
TagJSONError wraps the JSON error to one type.
Types ¶
type APIServiceGroup ¶
APIServiceGroup used to register the HTTP REST API.
func (*APIServiceGroup) Path ¶
func (sg *APIServiceGroup) Path() string
Path returns the path of the service.
type AccessPath ¶
AccessPath is used to identify HTTP api access path including path and method
func NewAccessPath ¶
func NewAccessPath(path, method string) AccessPath
NewAccessPath returns an AccessPath
type ComponentSignatureRoundTripper ¶
type ComponentSignatureRoundTripper struct {
// contains filtered or unexported fields
}
ComponentSignatureRoundTripper is used to add component signature in HTTP header
func NewComponentSignatureRoundTripper ¶
func NewComponentSignatureRoundTripper(roundTripper http.RoundTripper, componentName string) *ComponentSignatureRoundTripper
NewComponentSignatureRoundTripper returns a new ComponentSignatureRoundTripper.
type FieldError ¶
type FieldError struct {
// contains filtered or unexported fields
}
FieldError connects an error to a particular field
func ParseUint64VarsField ¶
func ParseUint64VarsField(vars map[string]string, varName string) (uint64, *FieldError)
ParseUint64VarsField connects strconv.ParseUint with request variables It hardcodes the base to 10 and bit size to 64 Any error returned will connect the requested field to the error via FieldError