server

package
v0.0.0-...-4cfa141 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Routes = map[Route]RouterArguments{
	CreateJob:     {Path: "/jobs", Method: http.MethodPost},
	StartJob:      {Path: "/jobs/{jobID}/start", Method: http.MethodPost},
	ListJobs:      {Path: "/jobs", Method: http.MethodGet},
	GetJobDetails: {Path: "/jobs/{jobID}", Method: http.MethodGet},
	DeleteJob:     {Path: "/jobs/{jobID}", Method: http.MethodDelete},
}

Routes defines a map between the routes and the routes' argument

Functions

func HTTPError

func HTTPError(w http.ResponseWriter, httpErr int, msg string, err error)

HTTPError is a helper to return errors on handlers

func JSONHandler

func JSONHandler(actual http.Handler) http.HandlerFunc

JSONHandler adds json headers

Types

type KaiServer

type KaiServer struct {
	net.Listener
	// contains filtered or unexported fields
}

KaiServer represents the server for processing all job requests

func New

func New(log *logging.Logger, config types.ServerConfig, listenNetwork string, listenAddr string, db db.Storage) *KaiServer

New creates a kai server

func (*KaiServer) CreateJob

func (ks *KaiServer) CreateJob(w http.ResponseWriter, r *http.Request)

CreateJob creates a job

func (*KaiServer) DeleteJob

func (ks *KaiServer) DeleteJob(w http.ResponseWriter, r *http.Request)

DeleteJob deletes a job

func (*KaiServer) GetJobDetails

func (ks *KaiServer) GetJobDetails(w http.ResponseWriter, r *http.Request)

GetJobDetails returns the details of a given job

func (*KaiServer) Handler

func (ks *KaiServer) Handler() http.Handler

Handler returns the router of the kai server

func (*KaiServer) ListJobs

func (ks *KaiServer) ListJobs(w http.ResponseWriter, r *http.Request)

ListJobs lists all jobs

func (*KaiServer) ServeHTTP

func (ks *KaiServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*KaiServer) Start

func (ks *KaiServer) Start(keep bool) error

Start starts the kai server

func (*KaiServer) StartJob

func (ks *KaiServer) StartJob(w http.ResponseWriter, r *http.Request)

StartJob triggers a recognition process

func (*KaiServer) Stop

func (ks *KaiServer) Stop() error

Stop stops the kai server

type Route

type Route int

Route defines all job routes

const (
	// CreateJob is the route for creating
	CreateJob Route = iota
	// StartJob is the route for starting
	StartJob
	// ListJobs is the route for listing
	ListJobs
	// GetJobDetails is the route for getting
	GetJobDetails
	// DeleteJob is the route for deleting
	DeleteJob
)

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router represents the routers of mux

func NewRouter

func NewRouter() *Router

NewRouter creates an new the router of mux

func (*Router) AddHandler

func (router *Router) AddHandler(args RouterArguments)

AddHandler adds a handler for a router

func (*Router) Handler

func (router *Router) Handler() http.Handler

Handler returns the handler of the router

type RouterArguments

type RouterArguments struct {
	Handler http.HandlerFunc
	Path    string
	Method  string
}

RouterArguments represents the mapping between path and method

Jump to

Keyboard shortcuts

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