api

package module
v1.2.0 Latest Latest
Warning

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

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

README

API

API responses in JSON format

  • Error(msg string)
  • ErrorWithData(msg string, data []interface)
  • Success(msg string)
  • SuccessWithData(msg string, data []interface)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Respond

func Respond(w http.ResponseWriter, r *http.Request, resp Response)

Respond writes a JSON or JSONP response

Types

type Response

type Response struct {
	Status  string                 `json:"status"`
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data"`
}

Response defines an response for the API

func Error

func Error(message string) Response

Error returns an error message

func ErrorWithData

func ErrorWithData(message string, data map[string]interface{}) Response

ErrorWithData returns an error message with data

func Forbidden added in v1.2.0

func Forbidden(message string) Response

Forbidden returns an forbidden message, user is authenticated but insufficient permissions

func Success

func Success(message string) Response

Success returns a success message

func SuccessWithData

func SuccessWithData(message string, data map[string]interface{}) Response

SuccessWithData returns a success message with data

func Unauthorized added in v1.2.0

func Unauthorized(message string) Response

Unauthorized returns an unauthorized message, user is not unauthorized

Jump to

Keyboard shortcuts

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