http

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

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 Conflict

func Conflict(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

Conflict will set the status code http.StatusConflict to the HTTP response message

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

func Forbidden(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

Forbidden will set the status code http.StatusForbidden to the HTTP response message

func InternalServerError

func InternalServerError(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

InternalServerError will set the status code http.StatusInternalServerError to the HTTP response message

func MethodNotAllow

func MethodNotAllow(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

MethodNotAllow will set the status code http.StatusMethodNotAllowed, to the HTTP response message

func NotAcceptable added in v0.2.7

func NotAcceptable(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

NotAcceptable will set the status code http.StatusNotAcceptable to the HTTP response message

func NotFound

func NotFound(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

NotFound will set the status code http.StatusNotFound to the HTTP response message

func OK

func OK(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

OK will set the status code http.StatusOK 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

func Unauthorized(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

Unauthorized will set the status code http.StatusUnauthorized to the HTTP response message

func UnprocessableEntity

func UnprocessableEntity(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error)

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

type ActionResponse struct {
	Error   bool   `json:"error"`
	Message string `json:"message"`
}

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

type RESTfulContextHandler func(*web.Context)

RESTfulContextHandler is the interface for restfuul handler(restful.Request,restful.Response)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL