Documentation ¶
Overview ¶
Package web is the interface between HTTP/HTTPS calls and the service layer. It acts as an intermediate router to call the correct service routine, depending upon the route called.
How Routing works: A route table is created that contains the HTTP Server routine to be called and the Service routine to be called. This acts as an interface layer to the services coded. It means that differnt interfaces (such as RPC) could be used by writing a different server later. This service layer allows mocking of routines by passing in a different map of what routines to call and what http requests can be answered.
Copyright 2014 Charles Gentry. All rights reserved. Please see the license included with this package
Index ¶
Constants ¶
const ( SRV_REGISTER = "/register/" SRV_LOGIN = "/login/" SRV_LOGOUT = "/logout/" SRV_AUTH = "/authenticate/" SRV_ENABLE = "/enable/" SRV_DISABLE = "/disable/" SRV_PING = "/ping/" SRV_UPDATE = "/update/" SRV_HOME = "/" SRV_TEST = "/test/" GUS_VERSION = "0.1" )
These constants provide the route string used in the http.Handle call.
Variables ¶
var RouteMap = RouteTable{ SRV_REGISTER: {Handler: httpCallService, Server: service.NewServiceRegister}, SRV_LOGIN: {Handler: httpCallService, Server: service.NewServiceLogin}, SRV_LOGOUT: {Handler: httpCallService, Server: service.NewServiceLogout}, SRV_AUTH: {Handler: httpCallService, Server: service.NewServiceAuthenticate}, SRV_UPDATE: {Handler: httpCallService, Server: service.NewServiceUpdate}, SRV_TEST: {Handler: httpCallService, Server: service.NewServiceTest}, SRV_PING: {Handler: httpPing, Server: nil}, SRV_HOME: {Handler: httpHome, Server: nil}, }
Functions ¶
This section is empty.
Types ¶
type RouteHandler ¶
type RouteHandler struct {
// contains filtered or unexported fields
}
func New ¶
func New(c *configure.Configure) *RouteHandler
New creates a new route handler. Route handlers setup the table used to map requests to a service function that will call the http Service routine
func (*RouteHandler) CreateHandlerFunc ¶
func (s *RouteHandler) CreateHandlerFunc(name string, rhandle RouteService) http.Handler
CreateHandlerFunc is a private function that creates an http.Handler function for the Go http.Handle function. This allows us to pass in extra parameters. The 'RouteService' gives us the linking points needed.
func (*RouteHandler) Register ¶
func (s *RouteHandler) Register(rmap RouteTable) *RouteHandler
Register all of the routes to the go handle. The process takes the RouteTable which consists of the http path to match and the RouteService. The route service entry holds the http function that will call the service function: path => http bundling routine -> (calls) -> ServiceRoute, which contains a run entry
func (*RouteHandler) Serve ¶
func (s *RouteHandler) Serve()
Serve starts listening and serving content.
type RouteService ¶
type RouteService struct { Handler RouteToService Server service.ServiceCreator }
RouteService defines a begining point (Handler) and what service we use (ServiceCreator)
type RouteTable ¶
type RouteTable map[string]RouteService
RouteTable contains a route name pointing to a service definition.
type RouteToService ¶
type RouteToService func(c *configure.Configure, rhandle RouteService, name string, w http.ResponseWriter, r *http.Request)
Route to service defines what a function needs to look like in order for us to call it when the route matches.