api

package
v0.0.0-...-b71cd7b Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(inner http.Handler) http.HandlerFunc

Logger is a decorator for a HTTP Request, adding logging functionality

func NewRouter

func NewRouter() *mux.Router

NewRouter returns a gorilla/mux router with a custom 404 handler.

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request)

NotFound is a 404 Message according to the Response type

func SendErrorJSON

func SendErrorJSON(w http.ResponseWriter, s int, m string)

Types

type Bird

type Bird struct {
	ID      int    `json:"id" bson:"id"`
	Name    string `json:"name" bson:"name"`
	Genus   string `json:"genus" bson:"genus"`
	Species string `json:"species" bson:"species"`
	TitleDE string `json:"title_de" bson:"title_de"`
	TitleEN string `json:"title_en" bson:"title_en"`
	DescDE  string `json:"desc_de" bson:"desc_de"`
	DescEN  string `json:"desc_en" bson:"desc_en"`
}

Bird defines a single Bird to retrieve info about

type Data

type Data struct {
	ID       int     `json:"id"`
	Accuracy float64 `json:"accuracy"`
}

Data defines the data field in the API response.

type Response

type Response struct {
	Status  int         `json:"status"`
	Message string      `json:"message"`
	Count   int         `json:"count"`
	Data    interface{} `json:"data"`
}

Response defines an API response.

func NewResponse

func NewResponse(s int, m string, c int, d interface{}) Response

NewResponse returns a Response with a passed message string and slice of Data. This will automatically set the Status field to 200.

func (Response) SendJSON

func (r Response) SendJSON(w http.ResponseWriter)

SendJSON encodes a Response as JSON and sends it on a passed http.ResponseWriter.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route is a helper type defining a specific Route

type Routes

type Routes []Route

Routes defines a slice of all available API Routes

type Server

type Server struct {
	Router   *mux.Router
	Session  *mgo.Session
	ModelURL string
}

Server defines holds information about routing and the Database sessions. Since all routes hang off the Server, handlers can easily access the database session.

func (*Server) DetectBinary

func (s *Server) DetectBinary() http.HandlerFunc

DetectBinary takes a application/octet-stream file via POST requests and forwards it to the API for detection

func (*Server) Dummy

func (s *Server) Dummy() http.HandlerFunc

Dummy sends a test Response mit randomized IDs and accuracies

func (*Server) GetAllBirds

func (s *Server) GetAllBirds() http.HandlerFunc

GetAllBirds returns all Bird info from the database, without descriptions. This needs to be limited with more birds (200+).

func (*Server) GetBirdByID

func (s *Server) GetBirdByID() http.HandlerFunc

GetBirdByID Retrieves a single Bird from the database.

func (*Server) Ping

func (s *Server) Ping() http.HandlerFunc

Ping sends a simple "Pong" as as JSON response

func (*Server) Routes

func (s *Server) Routes()

Routes defines all HTTP routes, hanging off the main Server struct. Like that, all routes have access to the Server's dependencies.

Jump to

Keyboard shortcuts

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