Documentation ¶
Index ¶
- Constants
- Variables
- func GetHTTPMethod(req *http.Request) int
- func GetHandler(wc WebController) func(w http.ResponseWriter, req *http.Request)
- func GetMethodID(method string) int
- func GetMethodName(m int) string
- func IsMethod(m int) bool
- type EndPoint
- type EndPoints
- type Message
- type Version
- type WebController
- type WebService
Constants ¶
const ( Options = iota Head Post Get Put Patch Delete Connect Trace )
HTTP Methods
Variables ¶
var BuildDate = "0001-01-01T00:00:00Z"
BuildDate is the date that this was compiled, or zeroes if no date is provided
var BuildTag = "dev"
BuildTag is the git hash of the build, or "dev" if no hash is provided
var HeartbeatRoute string = `/_heartbeat`
HeartbeatRoute is the path to the heartbeat endpoint
var VersionRoute string = `/_version`
VersionRoute is the path to the version information endpoint
Functions ¶
func GetHTTPMethod ¶
GetHTTPMethod returns the method ID for the method in a HTTP request
func GetHandler ¶
func GetHandler( wc WebController, ) func(w http.ResponseWriter, req *http.Request)
GetHandler returns a global handler for this route, to be used by the server mux
func GetMethodID ¶
GetMethodID returns an int value for a valid HTTP method name (upper-cased)
func GetMethodName ¶
GetMethodName returns the upper-cased method, i.e. GET for a given method int value
Types ¶
type EndPoints ¶
type EndPoints []EndPoint
EndPoints is a slice of all endpoints on this web service
type Message ¶
type Message struct {
Message string `json:"message"`
}
Message provides a simple JSON struct for serialising string messages as responses to calls that don't have a complex Type
type Version ¶
type Version struct { BuildTag string `json:"build"` BuildDate string `json:"buildDate"` Command string `json:"command"` }
Version is the base struct returned by the /version endpoint
type WebController ¶
type WebController struct { Route string // contains filtered or unexported fields }
WebController describes the HTTP method handlers for a given route. Create a WebController with service.NewController(route)
func NewWebController ¶
func NewWebController(route string) WebController
NewWebController creates a new controller for a given route
func (*WebController) AddMethodHandler ¶
func (wc *WebController) AddMethodHandler(m int, h func(w http.ResponseWriter, req *http.Request))
AddMethodHandler adds a HTTP handler to a given HTTP method
func (*WebController) GetAllowedMethods ¶
func (wc *WebController) GetAllowedMethods() string
GetAllowedMethods returns a comma-delimited string of HTTP methods allowed by this controller. This is determined by examining which methods have handlers assigned to them.
func (*WebController) GetMethodHandler ¶
func (wc *WebController) GetMethodHandler(m int) func(w http.ResponseWriter, req *http.Request)
GetMethodHandler returns the appropriate method handler for the request or a Method Not Allowed handler
type WebService ¶
type WebService struct {
// contains filtered or unexported fields
}
WebService represents a web server with a collection of controllers
func NewWebService ¶
func NewWebService() WebService
NewWebService provides a way to create a new blank WebService
func (*WebService) AddWebController ¶
func (ws *WebService) AddWebController(wc WebController)
AddWebController allows callees to add their controller. Note: The order in which the controllers are added is the order in which the routes will be applied.
func (*WebService) BuildRouter ¶
func (ws *WebService) BuildRouter() *mux.Router
BuildRouter collects all of the controllers, wires up the routes and returns the resulting router
func (*WebService) Run ¶
func (ws *WebService) Run(addr string)
Run collects all of the controllers, wires up the routes and starts the server