api

package
v0.0.0-...-e341e2a Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2015 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package containing the actual API functionality

Each file represents the API functionality for a certain database dbmodels (GET, POST, PUT, DELETE)

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
)

Variables

This section is empty.

Functions

func ApiHandler

func ApiHandler(rw http.ResponseWriter, req *http.Request)

All the requests to the server go through this handler.

This parses requests, filters them and takes appropriate actions based on the content and configuration of each http request.

The actions to be taken are stored in the Routes configuration of the application

func GiveApiMessage

func GiveApiMessage(statusCode int, message string, rw http.ResponseWriter)

Responds to the client that made the HTTP request with a status code and a simple message

func GiveApiResponse

func GiveApiResponse(statusCode int, message []byte, rw http.ResponseWriter)

Responds to the client that made the HTTP request with a status code and appropriate response data (usually JSON/XML encoded data)

func GiveApiStatus

func GiveApiStatus(statusCode int, rw http.ResponseWriter) string

Responds to the client that made the HTTP request with a status code and a default message for that status code

func PerformClientCall

func PerformClientCall(handlerName string, rw http.ResponseWriter, req *http.Request, route *config.Route)

Performs a call to the RPC server using the appropriate data extracted from the HTTP request, which is stored in the specific API variable

Types

type Api

type Api int

Used for defining a type representing the api

func (*Api) DeleteEndpoint

func (api *Api) DeleteEndpoint(vars *ApiVar, resp *ApiResponse) error

func (*Api) DeleteUserSession

func (api *Api) DeleteUserSession(vars *ApiVar, resp *ApiResponse) error

func (*Api) GenericDELETE

func (api *Api) GenericDELETE(vars *ApiVar, resp *ApiResponse) error

func (*Api) GenericGET

func (api *Api) GenericGET(vars *ApiVar, resp *ApiResponse) error

func (*Api) GenericPOST

func (api *Api) GenericPOST(vars *ApiVar, resp *ApiResponse) error

func (*Api) GenericPUT

func (api *Api) GenericPUT(vars *ApiVar, resp *ApiResponse) error

func (*Api) GetEndpoint

func (api *Api) GetEndpoint(vars *ApiVar, resp *ApiResponse) error

func (*Api) GetRequestsHistory

func (api *Api) GetRequestsHistory(vars *ApiVar, resp *ApiResponse) error

func (*Api) GetUserSession

func (api *Api) GetUserSession(vars *ApiVar, resp *ApiResponse) error

func (*Api) PostEndpoint

func (api *Api) PostEndpoint(vars *ApiVar, resp *ApiResponse) error

func (*Api) PostUser

func (api *Api) PostUser(vars *ApiVar, resp *ApiResponse) error

func (*Api) PostUserSession

func (api *Api) PostUserSession(vars *ApiVar, resp *ApiResponse) error

func (*Api) PutEndpoint

func (api *Api) PutEndpoint(vars *ApiVar, resp *ApiResponse) error

type ApiResponse

type ApiResponse struct {
	Message      []byte
	StatusCode   int
	ErrorMessage string
	ContentType  string
}

Data type containing important data that will be sent as response to HTTP requests

type ApiVar

type ApiVar struct {
	Route                config.Route
	RequestMethod        string
	RequestHeader        http.Header
	RequestForm          url.Values
	RequestContentLength int64
	RequestBody          []byte
	BasicAuth            BasicAuthentication
}

Data type containing important data from a HTTP request that has been made to the server

type BasicAuthentication

type BasicAuthentication struct {
	Username string
	Password string
	OK       bool
}

Data type containing the basic auth details

Jump to

Keyboard shortcuts

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