Documentation
¶
Index ¶
- type Communicator
- func (c Communicator) Error(message string)
- func (c Communicator) ErrorWithData(message string, data interface{})
- func (c Communicator) Fail(message string)
- func (c Communicator) FailWithData(message string, data interface{})
- func (c Communicator) OK(message string)
- func (c Communicator) OKWithData(message string, data interface{})
- type Response
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Communicator ¶
type Communicator struct {
// contains filtered or unexported fields
}
Communicator is an object used for sending JSON responses easily
func (Communicator) Error ¶
func (c Communicator) Error(message string)
Error is an alias for ErrorWithData(msg, nil), used for sending user created errors
func (Communicator) ErrorWithData ¶
func (c Communicator) ErrorWithData(message string, data interface{})
ErrorWithData creates a Response object with the given message and data, and then sends it to the user It should be used when an error caused by the server or an external library is thrown
func (Communicator) Fail ¶
func (c Communicator) Fail(message string)
Fail is an alias for FailWithData(msg, nil), used for user created errors
func (Communicator) FailWithData ¶
func (c Communicator) FailWithData(message string, data interface{})
FailWithData creates a Response object with the given message and data, and then sends it to the user It should be used for situations where the users input was the cause of a fault
func (Communicator) OK ¶
func (c Communicator) OK(message string)
OK is an alias for OKWithData(msg, nil), used for sending messages when everything is OK!
func (Communicator) OKWithData ¶
func (c Communicator) OKWithData(message string, data interface{})
OKWithData creates a Response object with the given message and data, and then sends it to the user It should only be used when everything is OK
type Response ¶
type Response struct {
Status Status `json:"status"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
Response is used as a general response for JSON rest requests
type Status ¶
type Status struct {
Code int `bson:"code" json:"code"`
Message string `bson:"message" json:"message"`
Error bool `bson:"error" json:"error"`
}
Status represents a general http error
func NewFailedStatus ¶
func NewFailedStatus() Status
NewFailedStatus returns a new Status object saying a request failed.
func NewForbiddenStatus ¶
func NewForbiddenStatus() Status
NewForbiddenStatus returns a new Status object detailing a failure of authorization.
func NewOKStatus ¶
func NewOKStatus() Status
NewOKStatus returns a new Status object with no errors.
func NewServerErrorStatus ¶
func NewServerErrorStatus() Status
NewServerErrorStatus returns a new Status object saying a server error has occured