Documentation ¶
Index ¶
- func Chain(f http.Handler, middlewares ...Middleware) http.Handler
- func Write(w http.ResponseWriter, status int, text string)
- func WriteBytes(w http.ResponseWriter, status int, text []byte)
- type App
- type AuthMiddleware
- type GameHandler
- type HealthcheckHandler
- type MetricsReporterMiddleware
- type Middleware
- type NewRelicMetricsReporter
- func (r *NewRelicMetricsReporter) EndDatastoreSegment(data map[string]interface{})
- func (r *NewRelicMetricsReporter) EndExternalSegment(data map[string]interface{})
- func (r *NewRelicMetricsReporter) EndSegment(data map[string]interface{}, name string)
- func (r *NewRelicMetricsReporter) StartDatastoreSegment(datastore, table, operation string) map[string]interface{}
- func (r *NewRelicMetricsReporter) StartExternalSegment(url string) map[string]interface{}
- func (r *NewRelicMetricsReporter) StartSegment(name string) map[string]interface{}
- type NewRelicMiddleware
- type OfferHandler
- type OfferRequestHandler
- type Pagination
- type ParamMiddleware
- type SentryMiddleware
- type ValidationMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(f http.Handler, middlewares ...Middleware) http.Handler
Chain applies middlewares to a http.HandlerFunc
func Write ¶
func Write(w http.ResponseWriter, status int, text string)
Write to the response and with the status code
func WriteBytes ¶
func WriteBytes(w http.ResponseWriter, status int, text []byte)
WriteBytes to the response and with the status code
Types ¶
type App ¶
type App struct { Address string Clock models.Clock Config *viper.Viper DB runner.Connection Debug bool Logger logrus.FieldLogger MetricsReporter middleware.MetricsReporter MaxAge int64 NewRelic newrelic.Application Router *mux.Router Server *http.Server Cache *cache.Cache OffersCacheMaxAge time.Duration Pagination *Pagination }
App is our API application
func NewApp ¶
func NewApp(host string, port int, config *viper.Viper, debug bool, logger logrus.FieldLogger, clock models.Clock) (*App, error)
NewApp ctor
func (*App) HandleError ¶
func (a *App) HandleError(w http.ResponseWriter, status int, msg string, err interface{})
HandleError writes an error response with message and status
type AuthMiddleware ¶
AuthMiddleware automatically adds a user email to the context
func (*AuthMiddleware) ServeHTTP ¶
func (m *AuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
func (*AuthMiddleware) SetNext ¶
func (m *AuthMiddleware) SetNext(next http.Handler)
SetNext middleware
type GameHandler ¶
GameHandler handler
func (*GameHandler) ServeHTTP ¶
func (g *GameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
type HealthcheckHandler ¶
type HealthcheckHandler struct {
App *App
}
HealthcheckHandler handler
func (*HealthcheckHandler) ServeHTTP ¶
func (h *HealthcheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
type MetricsReporterMiddleware ¶
MetricsReporterMiddleware handles logging
func (*MetricsReporterMiddleware) ServeHTTP ¶
func (m *MetricsReporterMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*MetricsReporterMiddleware) SetNext ¶
func (m *MetricsReporterMiddleware) SetNext(next http.Handler)
SetNext middleware
type Middleware ¶
Middleware contract
type NewRelicMetricsReporter ¶
type NewRelicMetricsReporter struct { App *App Transaction newrelic.Transaction }
NewRelicMetricsReporter reports metrics to new relic
func (*NewRelicMetricsReporter) EndDatastoreSegment ¶
func (r *NewRelicMetricsReporter) EndDatastoreSegment(data map[string]interface{})
EndDatastoreSegment stops segment
func (*NewRelicMetricsReporter) EndExternalSegment ¶
func (r *NewRelicMetricsReporter) EndExternalSegment(data map[string]interface{})
EndExternalSegment stops segment
func (*NewRelicMetricsReporter) EndSegment ¶
func (r *NewRelicMetricsReporter) EndSegment(data map[string]interface{}, name string)
EndSegment stops segment
func (*NewRelicMetricsReporter) StartDatastoreSegment ¶
func (r *NewRelicMetricsReporter) StartDatastoreSegment(datastore, table, operation string) map[string]interface{}
StartDatastoreSegment starts segment
func (*NewRelicMetricsReporter) StartExternalSegment ¶
func (r *NewRelicMetricsReporter) StartExternalSegment(url string) map[string]interface{}
StartExternalSegment starts segment
func (*NewRelicMetricsReporter) StartSegment ¶
func (r *NewRelicMetricsReporter) StartSegment(name string) map[string]interface{}
StartSegment starts segment
type NewRelicMiddleware ¶
NewRelicMiddleware handles logging
func (*NewRelicMiddleware) ServeHTTP ¶
func (m *NewRelicMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*NewRelicMiddleware) SetNext ¶
func (m *NewRelicMiddleware) SetNext(next http.Handler)
SetNext middleware
type OfferHandler ¶
OfferHandler handler
func (*OfferHandler) ServeHTTP ¶
func (g *OfferHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
type OfferRequestHandler ¶
OfferRequestHandler handler
func (*OfferRequestHandler) ServeHTTP ¶
func (h *OfferRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
type Pagination ¶
Pagination holds the page size (limit) and the offset that is the page number
type ParamMiddleware ¶
ParamMiddleware add into the model the parameters that came in the URI
func NewParamKeyMiddleware ¶
func NewParamKeyMiddleware(app *App, f func(string) bool) *ParamMiddleware
NewParamKeyMiddleware constructs a new param key middleware
func (*ParamMiddleware) ServeHTTP ¶
func (m *ParamMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*ParamMiddleware) SetNext ¶
func (m *ParamMiddleware) SetNext(next http.Handler)
SetNext handler
type SentryMiddleware ¶
type SentryMiddleware struct {
// contains filtered or unexported fields
}
SentryMiddleware adds the version to the request
func (*SentryMiddleware) ServeHTTP ¶
func (m *SentryMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
func (*SentryMiddleware) SetNext ¶
func (m *SentryMiddleware) SetNext(next http.Handler)
SetNext handler
type ValidationMiddleware ¶
type ValidationMiddleware struct { GetPayload func() interface{} // contains filtered or unexported fields }
ValidationMiddleware adds the version to the request
func NewValidationMiddleware ¶
func NewValidationMiddleware(f func() interface{}) *ValidationMiddleware
NewValidationMiddleware creates a new validation middleware
func (*ValidationMiddleware) ServeHTTP ¶
func (m *ValidationMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP method
func (*ValidationMiddleware) SetNext ¶
func (m *ValidationMiddleware) SetNext(next http.Handler)
SetNext handler