api

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 24 Imported by: 0

Documentation

Index

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

func (*App) ListenAndServe

func (a *App) ListenAndServe() (io.Closer, error)

ListenAndServe requests

type AuthMiddleware

type AuthMiddleware struct {
	App  *App
	Next http.Handler
	// contains filtered or unexported fields
}

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

type GameHandler struct {
	App    *App
	Method string
}

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

type MetricsReporterMiddleware struct {
	App  *App
	Next http.Handler
}

MetricsReporterMiddleware handles logging

func (*MetricsReporterMiddleware) ServeHTTP

func (*MetricsReporterMiddleware) SetNext

func (m *MetricsReporterMiddleware) SetNext(next http.Handler)

SetNext middleware

type Middleware

type Middleware interface {
	SetNext(http.Handler)
	http.Handler
}

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

type NewRelicMiddleware struct {
	App  *App
	Next http.Handler
}

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

type OfferHandler struct {
	App    *App
	Method string
}

OfferHandler handler

func (*OfferHandler) ServeHTTP

func (g *OfferHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP method

type OfferRequestHandler

type OfferRequestHandler struct {
	App    *App
	Method string
}

OfferRequestHandler handler

func (*OfferRequestHandler) ServeHTTP

func (h *OfferRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP method

type Pagination

type Pagination struct {
	Limit  uint64
	Offset uint64
}

Pagination holds the page size (limit) and the offset that is the page number

type ParamMiddleware

type ParamMiddleware struct {
	App       *App
	Validator func(string) bool
	Next      http.Handler
}

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

Jump to

Keyboard shortcuts

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