Documentation ¶
Index ¶
- func BadRequest(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContextHandler) http.HandlerFunc
- func Conflict(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func EncodeErrorPayload(req *http.Request, payload ErrorPayload) (out []byte, contentType string, encErr error)
- func Forbidden(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func InternalServerError(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func MethodNotAllow(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func NotFound(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func OK(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func RESTfulServiceHandler(sp *serviceprovider.Container, handler RESTfulContextHandler) restful.RouteFunction
- func Unauthorized(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func UnprocessableEntity(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)
- func WriteStatusAndError(req *http.Request, resp http.ResponseWriter, status int, errs ...error) (int, error)
- type ActionResponse
- type ErrorPayload
- type NativeContextHandler
- type RESTfulContextHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
BadRequest will set the status code http.StatusBadRequest to the HTTP response message
func CompositeServiceHandler ¶
func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContextHandler) http.HandlerFunc
CompositeServiceHandler apply mongo client to HandlerFunc
func EncodeErrorPayload ¶
func EncodeErrorPayload(req *http.Request, payload ErrorPayload) (out []byte, contentType string, encErr error)
EncodeErrorPayload is the function to get the error from the request and ErrorPayload It should contains the errorType and error content
func Forbidden ¶
Forbidden will set the status code http.StatusForbidden to the HTTP response message
func InternalServerError ¶
InternalServerError will set the status code http.StatusInternalServerError to the HTTP response message
func MethodNotAllow ¶
MethodNotAllow will set the status code http.StatusMethodNotAllowed, to the HTTP response message
func RESTfulServiceHandler ¶
func RESTfulServiceHandler(sp *serviceprovider.Container, handler RESTfulContextHandler) restful.RouteFunction
RESTfulServiceHandler is the wrapper to combine the RESTfulContextHandler with our serviceprovider object
func Unauthorized ¶
Unauthorized will set the status code http.StatusUnauthorized to the HTTP response message
func UnprocessableEntity ¶
UnprocessableEntity will set the status code http.StatusUnprocessableEntity to the HTTP response message
func WriteStatusAndError ¶
func WriteStatusAndError(req *http.Request, resp http.ResponseWriter, status int, errs ...error) (int, error)
WriteStatusAndError will write the error status and error code to the http request and return the written byte count of the http request
Example ¶
recorder := httptest.NewRecorder() request, err := http.NewRequest("POST", "http://here.com/v1/signin", nil) if err != nil { panic(err) } WriteStatusAndError(request, recorder, http.StatusBadRequest, errors.New("bad request"))
Output:
Types ¶
type ActionResponse ¶
ActionResponse is the structure for Response action
type ErrorPayload ¶
type ErrorPayload struct { XMLName xml.Name `json:"-" xml:"response"` Error bool `json:"error" xml:"error"` Message string `json:"message" xml:"message"` PreviousMessage string `json:"previousMessage,omitempty" xml:"previousMessage,omitempty"` }
ErrorPayload is the Structure to contain the Error Message from the HTTP response Contains the Error Messagess (At most two errors)
func NewErrorPayload ¶
func NewErrorPayload(errs ...error) ErrorPayload
NewErrorPayload will return the ErrorPayload message according the parameters (errors) The ErrorPayload contains at most error messages
type NativeContextHandler ¶
type NativeContextHandler func(*web.NativeContext)
NativeContextHandler is the interface for native http handler(http.Request and http.ResponseWriter)
type RESTfulContextHandler ¶
RESTfulContextHandler is the interface for restfuul handler(restful.Request,restful.Response)