communicator

package
v0.0.0-...-7bbe3ed Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2015 License: MIT Imports: 2 Imported by: 6 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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 New

NewComminicator returns a new communicator

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

Jump to

Keyboard shortcuts

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