Documentation
¶
Overview ¶
Package goa provides the runtime support for goa web applications.
see also http://goa.design
package cors: https://godoc.org/github.com/raphael/goa/cors
package design: https://godoc.org/github.com/raphael/goa/design
package dsl: https://godoc.org/github.com/raphael/goa/design/dsl
Code Generation ¶
goa applications development begins with writing the *design* of an application. The design is described using the goa language implemented by the github.com/raphael/goa/design/dsl package. The goagen tool consumes the metadata produced from executing the DSL to generate application specific code that glues the underlying HTTP server with action specific code and data structures.
The goa package contains supporting functionality for the generated code including basic request and response state management through the Context data structure, error handling via the application ErrorHandler field, middleware support via the Middleware data structure and finally input (and output) format validation algorithms.
Request Context ¶
The Context data structure provides access to both the request and response state. It implements the golang.org/x/net/Context interface so that deadlines and cancelation signals may also be implemented with it.
The request state is accessible through the Get, GetMany and Payload methods which return the values of the request parameters, query strings and request body. Action specific contexts wrap Context and expose properly typed fields corresponding to the request parameters and body data structure descriptions appearing in the design.
The response state can be accessed through the ResponseStatus, ResponseLength and Header methods. The Context type implements the http.ResponseWriter interface and thus action contexts can be used in places http.ResponseWriter can. Action contexts provide action specific helper methods that write the responses as described in the design optionally taking an instance of the media type for responses that contain a body.
Here is an example showing an "update" action corresponding to following design (extract):
Resource("bottle", func() { DefaultMedia(Bottle) Action("update", func() { Params(func() { Param("bottleID", Integer) }) Payload(UpdateBottlePayload) Response(OK) Response(NotFound) }) })
The action signature generated by goagen is:
type BottleController interface { Update(*UpdateBottleContext) error }
where UpdateBottleContext is:
type UpdateBottleContext struct { *goa.Context BottleID int Payload *UpdateBottlePayload }
and implements:
func (ctx *UpdateBottleContext) OK(resp *Bottle) error func (ctx *UpdateBottleContext) NotFound() error
The definitions of the Bottle and UpdateBottlePayload data structures are ommitted for brievity.
Error Handling ¶
The controller action methods generated by goagen such as the Update method of the BottleController interface shown above all return an error value. The application error handler function is invoked whenever the value returned by a controller action is not nil. The handler gets both the request context and the error as argument.
The default handler implementation returns a response with status code 500 containing the error message in the body. A different error handler can be specificied using the SetErrorHandler function. goa comes with an alternative error handler - the TerseErrorHandler - which also returns a response with status 500 but does not write the error message to the body of the response.
Middleware ¶
A goa middleware is a function that takes and returns a Handler. A Handler a the low level function which handles incoming HTTP requests. goagen generates the handlers code so each handler creates the action specific context and calls the controller action with it.
Middleware can be added to a goa application using the Application type Use method. goa comes with a few stock middleware that handle common needs such as logging, panic recovery or using the RequestID header to trace requests across multiple services.
Validation ¶
The goa design language documented in the dsl package makes it possible to attach validations to data structure definitions. One specific type of validation consists of defining the format that a data structure string field must follow. Example of formats include email, data time, hostnames etc. The ValidateFormat function provides the implementation for the format validation invoked from the code generated by goagen.
Package goa standardizes on structured error responses: a request that fails because of invalid input or unexpected condition produces a response that contains one or more structured error(s). Each error object has three keys: a id (number), a title and a message. The title for a given id is always the same, the intent is to provide a human friendly categorization. The message is specific to the error occurrence and provides additional details that often include contextual information (name of parameters etc.).
The basic data structure backing errors is TypedError which simply contains the id and message. Multiple errors (not just TypedError instances) can be encapsulated in a MultiError. Both TypedError and MultiError implement the error interface, the Error methods return valid JSON that can be written directly to a response body.
The code generated by goagen calls the helper functions exposed in this file when it encounters invalid data (wrong type, validation errors etc.) such as InvalidParamTypeError, InvalidAttributeTypeError etc. These methods take and return an error which is a MultiError that gets built over time. The final MultiError object then gets serialized into the response and sent back to the client. The response status code is inferred from the type wrapping the error object: a BadRequestError produces a 400 status code while any other error produce a 500. This behavior can be overridden by setting a custom ErrorHandler in the application.
Index ¶
- Constants
- Variables
- func Cancel()
- func DefaultErrorHandler(c *Context, e error)
- func Fatal(msg string, ctx ...interface{})
- func InvalidAttributeTypeError(ctx string, val interface{}, expected string, err error) error
- func InvalidEnumValueError(ctx string, val interface{}, allowed []interface{}, err error) error
- func InvalidFormatError(ctx, target string, format Format, formatError, err error) error
- func InvalidLengthError(ctx, target string, value int, min bool, err error) error
- func InvalidParamTypeError(name string, val interface{}, expected string, err error) error
- func InvalidPatternError(ctx, target string, pattern string, err error) error
- func InvalidRangeError(ctx string, target interface{}, value int, min bool, err error) error
- func MissingAttributeError(ctx, name string, err error) error
- func MissingHeaderError(name string, err error) error
- func MissingParamError(name string, err error) error
- func ReportError(err error, err2 error) error
- func TerseErrorHandler(c *Context, e error)
- func ValidateFormat(f Format, val string) error
- func ValidatePattern(p string, val string) bool
- type Application
- func (app *Application) HTTPHandler() http.Handler
- func (app *Application) ListenAndServe(addr string) error
- func (app *Application) ListenAndServeTLS(addr, certFile, keyFile string) error
- func (app *Application) Name() string
- func (app *Application) NewController(resName string) Controller
- func (app *Application) SetErrorHandler(handler ErrorHandler)
- func (app *Application) Use(m Middleware)
- type ApplicationController
- func (ctrl *ApplicationController) HandleError(ctx *Context, err error)
- func (ctrl *ApplicationController) MiddlewareChain() []Middleware
- func (ctrl *ApplicationController) NewHTTPRouterHandle(actName string, h Handler) httprouter.Handle
- func (ctrl *ApplicationController) SetErrorHandler(handler ErrorHandler)
- func (ctrl *ApplicationController) Use(m Middleware)
- type BadRequestError
- type Context
- func (ctx *Context) BadRequest(err *BadRequestError) error
- func (ctx *Context) Bug(format string, a ...interface{}) error
- func (ctx *Context) Get(name string) (string, bool)
- func (ctx *Context) GetMany(name string) []string
- func (ctx *Context) Header() http.Header
- func (ctx *Context) JSON(code int, body interface{}) error
- func (ctx *Context) Payload() interface{}
- func (ctx *Context) Request() *http.Request
- func (ctx *Context) Respond(code int, body []byte) error
- func (ctx *Context) ResponseLength() int
- func (ctx *Context) ResponseStatus() int
- func (ctx *Context) ResponseWritten() bool
- func (ctx *Context) SetValue(key, val interface{})
- func (ctx *Context) Write(body []byte) (int, error)
- func (ctx *Context) WriteHeader(code int)
- type Controller
- type ErrorHandler
- type ErrorID
- type Format
- type GracefulApplication
- type Handler
- type Middleware
- type MultiError
- type Service
- type TypedError
Constants ¶
const ( // ErrInvalidParamType is the error produced by the generated code when // a request parameter type does not match the design. ErrInvalidParamType = iota + 1 // ErrMissingParam is the error produced by the generated code when a // required request parameter is missing. ErrMissingParam // ErrInvalidAttributeType is the error produced by the generated // code when a data structure attribute type does not match the design // definition. ErrInvalidAttributeType // ErrMissingAttribute is the error produced by the generated // code when a data structure attribute required by the design // definition is missing. ErrMissingAttribute // ErrInvalidEnumValue is the error produced by the generated code when // a values does not match one of the values listed in the attribute // definition as being valid (i.e. not part of the enum). ErrInvalidEnumValue // ErrMissingHeader is the error produced by the generated code when a // required header is missing. ErrMissingHeader // ErrInvalidFormat is the error produced by the generated code when // a value does not match the format specified in the attribute // definition. ErrInvalidFormat // ErrInvalidPattern is the error produced by the generated code when // a value does not match the regular expression specified in the // attribute definition. ErrInvalidPattern // ErrInvalidRange is the error produced by the generated code when // a value is less than the minimum specified in the design definition // or more than the maximum. ErrInvalidRange // ErrInvalidLength is the error produced by the generated code when // a value is a slice with less elements than the minimum length // specified in the design definition or more elements than the // maximum length. ErrInvalidLength )
const ( // FormatDateTime defines RFC3339 date time values. FormatDateTime Format = "date-time" // FormatEmail defines RFC5322 email addresses. FormatEmail = "email" // FormatHostname defines RFC1035 Internet host names. FormatHostname = "hostname" // FormatIPv4 defines RFC2373 IPv4 address values. FormatIPv4 = "ipv4" // FormatIPv6 defines RFC2373 IPv6 address values. FormatIPv6 = "ipv6" // FormatURI defines RFC3986 URI values. FormatURI = "uri" // FormatMAC defines IEEE 802 MAC-48, EUI-48 or EUI-64 MAC address values. FormatMAC = "mac" // FormatCIDR defines RFC4632 and RFC4291 CIDR notation IP address values. FormatCIDR = "cidr" // FormatRegexp Regexp defines regular expression syntax accepted by RE2. FormatRegexp = "regexp" )
const ReqIDKey middlewareKey = 0
ReqIDKey is the RequestID middleware key used to store the request ID value in the context.
const RequestIDHeader = "X-Request-Id"
RequestIDHeader is the name of the header used to transmit the request ID.
Variables ¶
var ( // Log is the global logger from which other loggers (e.g. request specific loggers) are // derived. Configure it by setting its handler prior to calling New. // See https://godoc.org/github.com/inconshreveable/log15 Log log.Logger // RootContext is the root context from which all request contexts are derived. // Set values in the root context prior to starting the server to make these values // available to all request handlers: // // goa.RootContext = goa.RootContext.WithValue(key, value) // RootContext context.Context )
var InterruptSignals = []os.Signal{ os.Signal(syscall.SIGINT), os.Signal(syscall.SIGTERM), os.Signal(syscall.SIGQUIT), }
InterruptSignals is the list of signals that initiate graceful shutdown. Note that only SIGINT is supported on Windows so this list should be overridden by the caller when running on that platform.
Functions ¶
func Cancel ¶
func Cancel()
Cancel sends a cancellation signal to all handlers through the action context. see https://godoc.org/golang.org/x/net/context for details on how to handle the signal.
func DefaultErrorHandler ¶
DefaultErrorHandler returns a 400 response for request validation errors (instances of BadRequestError) and a 500 response for other errors. It writes the error message to the response body in both cases.
func Fatal ¶
func Fatal(msg string, ctx ...interface{})
Fatal logs a critical message and exits the process with status code 1. This function is meant to be used by initialization code to prevent the application from even starting up when something is obviously wrong. In particular this function should probably not be used when serving requests.
func InvalidAttributeTypeError ¶
InvalidAttributeTypeError appends a typed error of id ErrIncompatibleType to err and returns it.
func InvalidEnumValueError ¶
InvalidEnumValueError appends a typed error of id ErrInvalidEnumValue to err and returns it.
func InvalidFormatError ¶
InvalidFormatError appends a typed error of id ErrInvalidFormat to err and returns it.
func InvalidLengthError ¶
InvalidLengthError appends a typed error of id ErrInvalidLength to err and returns it.
func InvalidParamTypeError ¶
InvalidParamTypeError appends a typed error of id ErrInvalidParamType to err and returns it.
func InvalidPatternError ¶
InvalidPatternError appends a typed error of id ErrInvalidPattern to err and returns it.
func InvalidRangeError ¶
InvalidRangeError appends a typed error of id ErrInvalidRange to err and returns it.
func MissingAttributeError ¶
MissingAttributeError appends a typed error of id ErrMissingAttribute to err and returns it.
func MissingHeaderError ¶
MissingHeaderError appends a typed error of id ErrMissingHeader to err and returns it.
func MissingParamError ¶
MissingParamError appends a typed error of id ErrMissingParam to err and returns it.
func ReportError ¶
ReportError coerces the first argument into a MultiError then appends the second argument and returns the resulting MultiError.
func TerseErrorHandler ¶
TerseErrorHandler behaves like DefaultErrorHandler except that it does not set the response body for internal errors.
func ValidateFormat ¶
ValidateFormat validates a string against a standard format. It returns nil if the string conforms to the format, an error otherwise. The format specification follows the json schema draft 4 validation extension. see http://json-schema.org/latest/json-schema-validation.html#anchor105 Supported formats are: - "date-time": RFC3339 date time value - "email": RFC5322 email address - "hostname": RFC1035 Internet host name - "ipv4" and "ipv6": RFC2673 and RFC2373 IP address values - "uri": RFC3986 URI value - "mac": IEEE 802 MAC-48, EUI-48 or EUI-64 MAC address value - "cidr": RFC4632 and RFC4291 CIDR notation IP address value - "regexp": Regular expression syntax accepted by RE2
func ValidatePattern ¶
ValidatePattern returns an error if val does not match the regular expression p. It makes an effort to minimize the number of times the regular expression needs to be compiled.
Types ¶
type Application ¶
type Application struct { log.Logger // Application logger Router *httprouter.Router // Application router // contains filtered or unexported fields }
Application represents a goa application. At the basic level an application consists of a set of controllers, each implementing a given resource actions. goagen generates global functions - one per resource - that make it possible to mount the corresponding controller onto an application. An application contains the middleware, logger and error handler shared by all its controllers. Setting up an application might look like:
api := goa.New("my api") api.Use(SomeMiddleware()) rc := NewResourceController() rc.Use(SomeOtherMiddleware()) app.MountResourceController(api, rc) api.ListenAndServe(":80")
where NewResourceController returns an object that implements the resource actions as defined by the corresponding interface generated by goagen.
func (*Application) HTTPHandler ¶
func (app *Application) HTTPHandler() http.Handler
HTTPHandler returns a http.Handler to the service.
func (*Application) ListenAndServe ¶
func (app *Application) ListenAndServe(addr string) error
ListenAndServe starts a HTTP server and sets up a listener on the given host/port.
func (*Application) ListenAndServeTLS ¶
func (app *Application) ListenAndServeTLS(addr, certFile, keyFile string) error
ListenAndServeTLS starts a HTTPS server and sets up a listener on the given host/port.
func (*Application) NewController ¶
func (app *Application) NewController(resName string) Controller
NewController returns a controller for the given resource. This method is mainly intended for use by the generated code. User code shouldn't have to call it directly.
func (*Application) SetErrorHandler ¶
func (app *Application) SetErrorHandler(handler ErrorHandler)
SetErrorHandler defines an application wide error handler. The default error handler (DefaultErrorHandler) responds with a 500 status code and the error message in the response body. TerseErrorHandler provides an alternative implementation that does not write the error message to the response body for internal errors (e.g. for production). Set it with SetErrorHandler(TerseErrorHandler). Controller specific error handlers should be set using the Controller type SetErrorHandler method instead.
func (*Application) Use ¶
func (app *Application) Use(m Middleware)
Use adds a middleware to the application wide middleware chain. See NewMiddleware for wrapping goa and http handlers into goa middleware. goa comes with a set of commonly used middleware, see middleware.go. Controller specific middleware should be mounted using the Controller type Use method instead.
type ApplicationController ¶
type ApplicationController struct { log.Logger // Controller logger // contains filtered or unexported fields }
ApplicationController provides the common state and behavior for generated controllers.
func (*ApplicationController) HandleError ¶
func (ctrl *ApplicationController) HandleError(ctx *Context, err error)
HandleError invokes the controller error handler or - if there isn't one - the service error handler.
func (*ApplicationController) MiddlewareChain ¶
func (ctrl *ApplicationController) MiddlewareChain() []Middleware
MiddlewareChain returns the controller middleware chain.
func (*ApplicationController) NewHTTPRouterHandle ¶
func (ctrl *ApplicationController) NewHTTPRouterHandle(actName string, h Handler) httprouter.Handle
NewHTTPRouterHandle returns a httprouter handle from a goa handler. This handle initializes the request context by loading the request state, invokes the handler and in case of error invokes the controller (if there is one) or application error handler. This function is intended for the controller generated code. User code should not need to call it directly.
func (*ApplicationController) SetErrorHandler ¶
func (ctrl *ApplicationController) SetErrorHandler(handler ErrorHandler)
SetErrorHandler defines a controller specific error handler. When a controller action returns an error goa checks whether the controller is equipped with a error handler and if so calls it with the error given as argument. If there is no controller error handler then goa calls the application wide error handler instead.
func (*ApplicationController) Use ¶
func (ctrl *ApplicationController) Use(m Middleware)
Use adds a middleware to the controller. See NewMiddleware for wrapping goa and http handlers into goa middleware. goa comes with a set of commonly used middleware, see middleware.go.
type BadRequestError ¶
type BadRequestError struct {
Actual error
}
BadRequestError is the type of errors that result in a response with status code 400.
func NewBadRequestError ¶
func NewBadRequestError(err error) *BadRequestError
NewBadRequestError wraps the given error into a BadRequestError.
type Context ¶
Context is the object that provides access to the underlying HTTP request and response state. Context implements http.ResponseWriter and also provides helper methods for writing HTTP responses. It also implements the context.Context interface described at http://blog.golang.org/context.
func NewContext ¶
func NewContext(gctx context.Context, req *http.Request, rw http.ResponseWriter, params map[string]string, query map[string][]string, payload interface{}) *Context
NewContext builds a goa context from the given context.Context and request state. If gctx is nil then context.Background is used instead.
func (*Context) BadRequest ¶
func (ctx *Context) BadRequest(err *BadRequestError) error
BadRequest sends a HTTP response with status code 400 and the given error as body.
func (*Context) Bug ¶
Bug sends a HTTP response with status code 500 and the given body. The body can be set using a format and substituted values a la fmt.Printf.
func (*Context) Get ¶
Get returns the param or query string with the given name and true or an empty string and false if there isn't one.
func (*Context) GetMany ¶
GetMany returns the query string values with the given name or nil if there aren't any.
func (*Context) Header ¶
Header returns the response header. It implements the http.ResponseWriter interface.
func (*Context) JSON ¶
JSON serializes the given body into JSON and sends a HTTP response with the given status code and JSON as body.
func (*Context) Payload ¶
func (ctx *Context) Payload() interface{}
Payload returns the deserialized request body or nil if body is empty.
func (*Context) Respond ¶
Respond writes the given HTTP status code and response body. This method should only be called once per request.
func (*Context) ResponseLength ¶
ResponseLength returns the response body length in bytes if the response was written to the context via one of the response methods (Respond, JSON, BadRequest, Bug), 0 otherwise.
func (*Context) ResponseStatus ¶
ResponseStatus returns the response status if it was set via one of the context response methods (Respond, JSON, BadRequest, Bug), 0 otherwise.
func (*Context) ResponseWritten ¶
ResponseWritten returns true if an HTTP response was written.
func (*Context) SetValue ¶
func (ctx *Context) SetValue(key, val interface{})
SetValue sets the value associated with key in the context. The value can be retrieved using the Value method. Note that this changes the underlying context.Context object and thus clients holding a reference to that won't be able to access the new value. It's probably a bad idea to hold a reference to the inner context anyway...
func (*Context) Write ¶
Write writes the HTTP response body. It implements the http.ResponseWriter interface.
func (*Context) WriteHeader ¶
WriteHeader writes the HTTP status code to the response. It implements the http.ResponseWriter interface.
type Controller ¶
type Controller interface { // Use adds a middleware to the controller middleware chain. // It is a convenient method for doing append(ctrl.MiddlewareChain(), m) Use(Middleware) // MiddlewareChain returns the controller middleware chain including the // service-wide middleware. MiddlewareChain() []Middleware // SetErrorHandler sets the controller specific error handler. SetErrorHandler(ErrorHandler) // NewHTTPRouterHandle returns a httprouter handle from a goa handler. // This function is intended for the controller generated code. // User code should not need to call it directly. NewHTTPRouterHandle(actName string, h Handler) httprouter.Handle }
Controller is the interface implemented by all goa controllers. A controller implements a given resource actions. There is a one-to-one relationship between designed resources and generated controllers. Controllers may override the service wide error handler and be equipped with controller specific middleware.
type ErrorHandler ¶
ErrorHandler defines the application error handler signature.
type GracefulApplication ¶
type GracefulApplication struct { *Application sync.Mutex // Interrupted is true if the application is in the process of shutting down. Interrupted bool // contains filtered or unexported fields }
GracefulApplication is a goa application using a graceful shutdown server. When sending any of the signals listed in InterruptSignals to the process GracefulApplication:
* disables keepalive connections.
* closes the listening socket, allowing another process to listen on that port immediately.
* calls Cancel, signaling all active handlers.
func (*GracefulApplication) ListenAndServe ¶
func (gapp *GracefulApplication) ListenAndServe(addr string) error
ListenAndServe starts the HTTP server and sets up a listener on the given host/port.
func (*GracefulApplication) ListenAndServeTLS ¶
func (gapp *GracefulApplication) ListenAndServeTLS(addr, certFile, keyFile string) error
ListenAndServeTLS starts a HTTPS server and sets up a listener on the given host/port.
func (*GracefulApplication) Shutdown ¶
func (gapp *GracefulApplication) Shutdown() bool
Shutdown initiates graceful shutdown of the running server once. Returns true on initial shutdown and false if already shutting down.
type Handler ¶
Handler defines the controller handler signatures. Controller handlers accept a context and return an error. The context provides typed access to the request and response state. It implements the golang.org/x/net/context package Context interface so that handlers may define deadlines and cancelation signals - see the Timeout middleware as an example. If a controller handler returns an error then the application error handler is invoked with the request context and the error. The error handler is responsible for writing the HTTP response. See DefaultErrorHandler and TerseErrorHandler.
type Middleware ¶
Middleware represents the canonical goa middleware signature.
func LogRequest ¶
func LogRequest() Middleware
LogRequest creates a request logger middleware. This middleware is aware of the RequestID middleware and if registered after it leverages the request ID for logging.
func NewMiddleware ¶
func NewMiddleware(m interface{}) (mw Middleware, err error)
NewMiddleware creates a middleware from the given argument. The allowed types for the argument are:
- a goa middleware: goa.Middleware or func(goa.Handler) goa.Handler
- a goa handler: goa.Handler or func(*goa.Context) error
- an http middleware: func(http.Handler) http.Handler
- or an http handler: http.Handler or func(http.ResponseWriter, *http.Request)
An error is returned if the given argument is not one of the types above.
func Recover ¶
func Recover() Middleware
Recover is a middleware that recovers panics and returns an internal error response.
func RequestID ¶
func RequestID() Middleware
RequestID is a middleware that injects a request ID into the context of each request. Retrieve it using ctx.Value(ReqIDKey). If the incoming request has a RequestIDHeader header then that value is used else a random value is generated.
func RequireHeader ¶
func RequireHeader( pathPattern *regexp.Regexp, requiredHeaderName string, requiredHeaderValue *regexp.Regexp, failureStatus int) Middleware
RequireHeader requires a request header to match a value pattern. If the header is missing or does not match then the failureStatus is the response (e.g. http.StatusUnauthorized). If pathPattern is nil then any path is included. If requiredHeaderValue is nil then any value is accepted so long as the header is non-empty.
func Timeout ¶
func Timeout(timeout time.Duration) Middleware
Timeout sets a global timeout for all controller actions. The timeout notification is made through the context, it is the responsability of the request handler to handle it. For example:
func (ctrl *Controller) DoLongRunningAction(ctx *DoLongRunningActionContext) error { action := NewLongRunning() // setup long running action c := make(chan error, 1) // create return channel go func() { c <- action.Run() } // Launch long running action goroutine select { case <- ctx.Done(): // timeout triggered action.Cancel() // cancel long running action <-c // wait for Run to return. return ctx.Err() // retrieve cancel reason case err := <-c: // action finished on time return err // forward its return value } }
Package golang.org/x/net/context/ctxhttp contains an implementation of an HTTP client which is context-aware:
func (ctrl *Controller) HttpAction(ctx *HttpActionContext) error { req, err := http.NewRequest("GET", "http://iamaslowservice.com", nil) // ... resp, err := ctxhttp.Do(ctx, nil, req) // returns if timeout triggers // ... }
Controller actions can check if a timeout is set by calling the context Deadline method.
type MultiError ¶
type MultiError []error
MultiError records multiple errors.
func (MultiError) Error ¶
func (m MultiError) Error() string
Error summarizes all the underlying error messages in one JSON array.
type Service ¶
type Service interface { // Logging methods, configure the log handler using the Logger global variable. log.Logger // Name is the name of the goa application. Name() string // SetErrorHandler allows setting the service-wide error handler. SetErrorHandler(ErrorHandler) // Use adds a middleware to the service-wide middleware chain. Use(m Middleware) // ListenAndServe starts a HTTP server on the given port. ListenAndServe(addr string) error // ListenAndServeTLS starts a HTTPS server on the given port. ListenAndServeTLS(add, certFile, keyFile string) error // HTTPHandler returns a http.Handler interface to the underlying service. // Note: using the handler directly bypasses the graceful shutdown behavior of // services instantiated with NewGraceful. HTTPHandler() http.Handler // NewController returns a controller for the resource with the given name. // This method is mainly intended for use by generated code. NewController(resName string) Controller }
Service is the interface implemented by all goa services. It provides methods for configuring a service and running it.
func NewGraceful ¶
NewGraceful returns a goa application that uses a graceful shutdown server.
type TypedError ¶
TypedError describes an error that can be returned in a HTTP response.
func (*TypedError) Error ¶
func (t *TypedError) Error() string
Error builds an error message from the typed error details.
func (*TypedError) MarshalJSON ¶
func (t *TypedError) MarshalJSON() ([]byte, error)
MarshalJSON implements the json marshaler interface.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package cors provides a goa middleware that implements the Cross-Origin Resource Sharing (CORS) standard as defined by W3C (http://www.w3.org/TR/access-control/).
|
Package cors provides a goa middleware that implements the Cross-Origin Resource Sharing (CORS) standard as defined by W3C (http://www.w3.org/TR/access-control/). |
Package design defines types which describe the data types used by action controllers.
|
Package design defines types which describe the data types used by action controllers. |
dsl
Package dsl implements the goa design language.
|
Package dsl implements the goa design language. |
dsl/test
Package test contains a self-contained DSL test.
|
Package test contains a self-contained DSL test. |
examples
|
|
codegen
Package codegen contains common code used by all code generators.
|
Package codegen contains common code used by all code generators. |
gen_gen
Package gengen provides goagen with the ability to run user provided generators.
|
Package gengen provides goagen with the ability to run user provided generators. |
gen_main
Package genmain provides a generator for a skeleton goa application.
|
Package genmain provides a generator for a skeleton goa application. |
gen_schema
Package genschema provides a generator for the JSON schema controller.
|
Package genschema provides a generator for the JSON schema controller. |
gen_swagger
Package genswagger provides a generator for the JSON swagger controller.
|
Package genswagger provides a generator for the JSON swagger controller. |
meta
Package meta is used to bootstrap the code generator.
|
Package meta is used to bootstrap the code generator. |