output

package
v0.0.0-...-5024c58 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrURLParams is the error code for bad data in the URL parameters
	ErrURLParams = errors.New("Invalid url parameters")

	ErrUserNotLogged = errors.New("User not logged in")

	//ErrInsertingData is the error code for error when inserting data on the database
	ErrInsertingData = errors.New("Error inserting data")

	//ErrInternalServer is the error code for internal server error, this is the error returned by default if none of the errors match the one used
	ErrInternalServer = errors.New("Yep, server fucked :(")

	//ErrNoContentFound is the error code for a request that has been performed correctly but has not found data on the database
	ErrNoContentFound = errors.New("No content found")

	//ErrInvalidToken is the error code for an invalid json web token
	ErrInvalidToken = errors.New("Token invalid")

	//ErrMalformedToken is the error code for a json web token with a wrong structure
	ErrMalformedToken = errors.New("Token malformed")

	//ErrMissingToken is the error code for a missing json web token on the request headers
	ErrMissingToken = errors.New("Missing auth token")

	//ErrWrongBasicAuth is the error code for a wrong authentication using basicAuth
	ErrWrongBasicAuth = errors.New("Invalid username or password")

	//ErrBodyParams is the error code for wrong parameters in the request body
	ErrBodyParams = errors.New("Invalid request payload")

	//ErrFetchResponse is the error for a response that fails using the implemented Fetch function
	ErrFetchResponse = errors.New("The fetch call did not return success")

	//ErrTooManyRequests is the error for when a user has performed too many requests and is rate limited
	ErrTooManyRequests = errors.New("Request limit exceeded, try again in a few seconds")

	//ErrTooMuchData is the error for when a user has performed too many requests and is rate limited
	ErrTooMuchData = errors.New("Too much data sent, the maximum is 500 elements per request")

	//SuccessResource is the code for when a resource is created successfully
	SuccessResource = string("Resource created correctly")
)

Functions

func ErrorCodeMessage

func ErrorCodeMessage(_err error) (int, string)

ErrorCodeMessage returns an http error and a message for a particular error This function is called in respondwitherror to determine the user error message

func RespondWithError

func RespondWithError(_w http.ResponseWriter, _err error)

RespondWithError returns an error specified by the _code parameter which corresponds to the http error

func RespondWithJSON

func RespondWithJSON(_w http.ResponseWriter, _code int, payload interface{})

RespondWithJSON writes the json response to return to the user, it contains the following fields

- timestamp: time at the request was made

- data: data of the request

- Content-Type: format of the response

Types

type ItemDataRDB

type ItemDataRDB struct {
	StringField string   `json:"stringField",rethinkdb:"stringField",omitempty`
	ListField   []string `json:"listField",rethinkdb:"listField,omitempty`
	IntField    int      `json:"intField",rethinkdb:"intField",omitempty`
	BoolField   bool     `json:"boolField",rethinkdb:"boolField",omitempty`

	ID string `json:"id",rethinkdb:"id",omitempty`
}

Jump to

Keyboard shortcuts

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