コード例 #1
0
ファイル: http.go プロジェクト: yourchanges/empire
func NewHTTPHandler(r *Relay) http.Handler {
	m := httpx.NewRouter()

	m.Handle("POST", "/containers", &PostContainers{r})

	var h httpx.Handler

	// Handle errors
	errorHandler := func(err error, w http.ResponseWriter, r *http.Request) {
		Error(w, err, http.StatusInternalServerError)
	}

	h = middleware.HandleError(m, errorHandler)

	// Recover from panics.
	h = middleware.Recover(h, reporter.NewLogReporter())

	// Add a logger to the context.
	h = middleware.NewLogger(h, os.Stdout)

	// Add the request id to the context.
	h = middleware.ExtractRequestID(h)

	// Wrap the route in middleware to add a context.Context.
	return middleware.BackgroundContext(h)
}
コード例 #2
0
ファイル: factories.go プロジェクト: iserko/empire
func newHBReporter(key, env string) (reporter.Reporter, error) {
	r := hb.NewReporter(key)
	r.Environment = env

	// Append here because `go vet` will complain about unkeyed fields,
	// since it thinks MultiReporter is a struct literal.
	return append(reporter.MultiReporter{}, reporter.NewLogReporter(), r), nil
}
コード例 #3
0
ファイル: factories.go プロジェクト: iserko/empire
func newReporter(c *Context) (reporter.Reporter, error) {
	u := c.String(FlagReporter)
	if u == "" {
		return reporter.NewLogReporter(), nil
	}

	uri, err := url.Parse(u)
	if err != nil {
		return nil, err
	}

	switch uri.Scheme {
	case "hb":
		log.Println("Using Honeybadger to report errors")
		q := uri.Query()
		return newHBReporter(q.Get("key"), q.Get("environment"))
	default:
		panic(fmt.Errorf("unknown reporter: %s", u))
	}
}
コード例 #4
0
ファイル: empire.go プロジェクト: intfrr/empire
	"github.com/jinzhu/gorm"
	"github.com/remind101/empire/pkg/dockerutil"
	"github.com/remind101/empire/pkg/image"
	"github.com/remind101/empire/procfile"
	"github.com/remind101/empire/scheduler"
	"github.com/remind101/pkg/reporter"
	"golang.org/x/net/context"
)

var (
	// DefaultOptions is a default Options instance that can be passed when
	// intializing a new Empire.
	DefaultOptions = Options{}

	// DefaultReporter is the default reporter.Reporter to use.
	DefaultReporter = reporter.NewLogReporter()
)

const (
	// WebPort is the default PORT to set on web processes.
	WebPort = 8080

	// WebProcessType is the process type we assume are web server processes.
	WebProcessType = "web"
)

// ProcfileExtractor is a function that can extract a Procfile from an image.
type ProcfileExtractor func(context.Context, image.Image, io.Writer) (procfile.Procfile, error)

// Options is provided to New to configure the Empire services.
type Options struct {