goa

package
v0.0.0-...-ab88fb7 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package goa contains middleware for monitoring Goa applications.

The provided middleware works in the same way as compass/http.

Example usage:

// Get hooks and resolver for the middleware.
hooks := prom.NewHooks(nil)
resolver := NewContextResolver()

// Create the middleware.
mw, err := NewMiddleware(hooks, resolver)
if err != nil {
	panic(err)
}

// Use the middleware in a service.
svc := goa.New("example")
svc.Use(mw)
svc.ListenAndServe(":8080")

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustNewMiddleware

func MustNewMiddleware(hooks mhttp.Hooks, resolver mhttp.Resolver) goa.Middleware

MustNewMiddleware is like NewMiddleware, except it panics where NewMiddleware would return an error.

Example
package main

import (
	"net/http"

	"github.com/goadesign/goa"
	mgoa "github.com/zenreach/compass/goa"
	mhttp "github.com/zenreach/compass/http"
)

func main() {
	// To keep this simply our hooks won't do anything.
	hooks := &NilHooks{}

	// Create a resolver to name our endpoint "hello".
	resolver := mhttp.ResolverFunc(func(*http.Request) string {
		return "hello"
	})

	// Create the Goa service, assign our middleware, and run it.
	svc := goa.New("example")
	svc.Use(mgoa.MustNewMiddleware(hooks, resolver))
	svc.ListenAndServe(":8080")
}

// NilHooks implements http.Hooks as a set of noops.
type NilHooks struct{}

func (*NilHooks) RequestHook(endpoint string, req *http.Request) {}

func (*NilHooks) ResponseHook(endpoint string, req *http.Request, res *mhttp.Response) {}
Output:

func NewMiddleware

func NewMiddleware(hooks mhttp.Hooks, resolver mhttp.Resolver) (goa.Middleware, error)

NewMiddleware creates a Goa middleware which calls the provided hooks during the request cycle. This must be used as the net/http middleware produced by http.NewMiddleware is incompatible with Goa.

Types

This section is empty.

Jump to

Keyboard shortcuts

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