api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2016 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDonationHandler

func CreateDonationHandler(app *App) func(c echo.Context) error

CreateDonationHandler is the handler responsible for creating donation requests

func CreateDonationRequestHandler

func CreateDonationRequestHandler(app *App) func(c echo.Context) error

CreateDonationRequestHandler is the handler responsible for creating donation requests

func FailWith

func FailWith(status int, message string, c echo.Context) error

FailWith fails with the specified message

func GetDonationWeightByClanHandler

func GetDonationWeightByClanHandler(app *App) func(c echo.Context) error

GetDonationWeightByClanHandler is the handler responsible for creating donation requests

func GetRequestBody

func GetRequestBody(c echo.Context) ([]byte, error)

GetRequestBody from echo context

func GetRequestJSON

func GetRequestJSON(payloadStruct interface{}, c echo.Context) error

GetRequestJSON as the specified interface from echo context

func GetTX

GetTX returns new relic transaction

func HealthCheckHandler

func HealthCheckHandler(app *App) func(c echo.Context) error

HealthCheckHandler is the handler responsible for validating that the app is still up

func LoadJSONPayload

func LoadJSONPayload(payloadStruct interface{}, c echo.Context, l zap.Logger) error

LoadJSONPayload loads the JSON payload to the given struct validating all fields are not null

func SucceedWith

func SucceedWith(payload map[string]interface{}, c echo.Context) error

SucceedWith sends payload to user with status 200

func UpdateGameHandler

func UpdateGameHandler(app *App) func(c echo.Context) error

UpdateGameHandler is the handler responsible for updating games

func UpsertItemHandler

func UpsertItemHandler(app *App) func(c echo.Context) error

UpsertItemHandler is the handler responsible for creating/updating items

func ValidatePayload

func ValidatePayload(payload Validatable) []string

ValidatePayload for any validatable payload

func WithSegment

func WithSegment(name string, c echo.Context, f func() error) error

WithSegment adds a segment to new relic transaction

Types

type App

type App struct {
	Debug        bool
	Port         int
	Host         string
	ConfigPath   string
	App          *echo.Echo
	Engine       engine.Server
	Config       *viper.Viper
	MongoDb      *mgo.Database
	MongoSession *mgo.Session
	Logger       zap.Logger
	Background   bool
	Fast         bool
	Redsync      *redsync.Redsync
	Redis        redis.Conn
	NewRelic     newrelic.Application
}

App is a struct that represents a Donations Api APP

func GetApp

func GetApp(host string, port int, configPath string, debug bool, logger zap.Logger, background bool, fast bool) (*App, error)

GetApp returns a new Donations Application

func (*App) Configure

func (app *App) Configure() error

Configure instantiates the required dependencies for Donations Application

func (*App) GetMutex

func (app *App) GetMutex(name string, retries, timeout int) *redsync.Mutex

GetMutex returns a lock for a given name

func (*App) OnErrorHandler

func (app *App) OnErrorHandler(err error, stack []byte)

OnErrorHandler handles application panics

func (*App) Start

func (app *App) Start()

Start starts listening for web requests at specified host and port

func (*App) Stop

func (app *App) Stop()

Stop app running routines

type BodyExtractionMiddleware

type BodyExtractionMiddleware struct{}

func NewBodyExtractionMiddleware

func NewBodyExtractionMiddleware() *BodyExtractionMiddleware

NewBodyExtractionMiddleware with API version

func (*BodyExtractionMiddleware) Serve

Serve serves the middleware

type CreateDonationRequestPayload

type CreateDonationRequestPayload struct {
	Item   string `json:"item"`
	Player string `json:"player"`
	Clan   string `json:"clan"`
}

CreateDonationRequestPayload maps the payload for the Create Game route

func (CreateDonationRequestPayload) MarshalEasyJSON

func (v CreateDonationRequestPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*CreateDonationRequestPayload) ToJSON

func (cdrp *CreateDonationRequestPayload) ToJSON() ([]byte, error)

ToJSON returns the payload as JSON

func (*CreateDonationRequestPayload) UnmarshalEasyJSON

func (v *CreateDonationRequestPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CreateDonationRequestPayload) Validate

func (cdrp *CreateDonationRequestPayload) Validate() []string

Validate all the required fields for creating a game

type DonationPayload

type DonationPayload struct {
	Player             string `json:"player"`
	Amount             int    `json:"amount"`
	MaxWeightPerPlayer int    `json:"maxWeightPerPlayer"`
}

DonationPayload maps the payload for the Create Game route

func (DonationPayload) MarshalEasyJSON

func (v DonationPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*DonationPayload) ToJSON

func (dp *DonationPayload) ToJSON() ([]byte, error)

ToJSON returns the payload as JSON

func (*DonationPayload) UnmarshalEasyJSON

func (v *DonationPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*DonationPayload) Validate

func (dp *DonationPayload) Validate() []string

Validate all the required fields for creating a game

type EasyJSONMarshaler

type EasyJSONMarshaler interface {
	MarshalEasyJSON(w *jwriter.Writer)
}

EasyJSONMarshaler describes a struct able to marshal json

type EasyJSONUnmarshaler

type EasyJSONUnmarshaler interface {
	UnmarshalEasyJSON(l *jlexer.Lexer)
}

EasyJSONUnmarshaler describes a struct able to unmarshal json

type LoggerMiddleware

type LoggerMiddleware struct {
	Logger zap.Logger
}

LoggerMiddleware is responsible for logging to Zap all requests

func NewLoggerMiddleware

func NewLoggerMiddleware(theLogger zap.Logger) *LoggerMiddleware

NewLoggerMiddleware returns the logger middleware

func (*LoggerMiddleware) Serve

Serve serves the middleware

type NewRelicMiddleware

type NewRelicMiddleware struct {
	App    *App
	Logger zap.Logger
}

NewRelicMiddleware is responsible for logging to Zap all requests

func NewNewRelicMiddleware

func NewNewRelicMiddleware(app *App, theLogger zap.Logger) *NewRelicMiddleware

NewNewRelicMiddleware returns the logger middleware

func (*NewRelicMiddleware) Serve

Serve serves the middleware

type RecoveryMiddleware

type RecoveryMiddleware struct {
	OnError func(error, []byte)
}

RecoveryMiddleware recovers from errors

func NewRecoveryMiddleware

func NewRecoveryMiddleware(onError func(error, []byte)) *RecoveryMiddleware

NewRecoveryMiddleware returns a configured middleware

func (*RecoveryMiddleware) Serve

Serve executes on error handler when errors happen

type SentryMiddleware

type SentryMiddleware struct {
	App *App
}

SentryMiddleware is responsible for sending all exceptions to sentry

func NewSentryMiddleware

func NewSentryMiddleware(app *App) *SentryMiddleware

NewSentryMiddleware returns a new sentry middleware

func (*SentryMiddleware) Serve

Serve serves the middleware

type UpdateGamePayload

type UpdateGamePayload struct {
	Name                         string `json:"name"`
	DonationCooldownHours        int    `json:"donationCooldownHours" bson:"donationCooldownHours"`
	DonationRequestCooldownHours int    `json:"donationRequestCooldownHours" bson:"donationRequestCooldownHours"`
}

UpdateGamePayload maps the payload for the Create Game route

func (UpdateGamePayload) MarshalEasyJSON

func (v UpdateGamePayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*UpdateGamePayload) ToJSON

func (ugp *UpdateGamePayload) ToJSON() ([]byte, error)

ToJSON returns the payload as JSON

func (*UpdateGamePayload) UnmarshalEasyJSON

func (v *UpdateGamePayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*UpdateGamePayload) Validate

func (ugp *UpdateGamePayload) Validate() []string

Validate all the required fields for updating a game

type UpsertItemPayload

type UpsertItemPayload struct {
	Metadata                          map[string]interface{} `json:"metadata"`
	WeightPerDonation                 int                    `json:"weightPerDonation"`
	LimitOfItemsPerPlayerDonation     int                    `json:"limitOfItemsPerPlayerDonation"`
	LimitOfItemsInEachDonationRequest int                    `json:"limitOfItemsInEachDonationRequest"`
}

UpsertItemPayload maps the payload for the Upsert Item route

func (UpsertItemPayload) MarshalEasyJSON

func (v UpsertItemPayload) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*UpsertItemPayload) ToJSON

func (uip *UpsertItemPayload) ToJSON() ([]byte, error)

ToJSON returns the payload as JSON

func (*UpsertItemPayload) UnmarshalEasyJSON

func (v *UpsertItemPayload) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*UpsertItemPayload) Validate

func (uip *UpsertItemPayload) Validate() []string

Validate all the required fields for creating a game

type Validatable

type Validatable interface {
	Validate() []string
}

Validatable indicates that a struct can be validated

type Validation

type Validation struct {
	// contains filtered or unexported fields
}

Validation struct

func NewValidation

func NewValidation() *Validation

NewValidation for validating structs

func (*Validation) Errors

func (v *Validation) Errors() []string

Errors in validation

func (Validation) MarshalEasyJSON

func (v Validation) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*Validation) UnmarshalEasyJSON

func (v *Validation) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

type VersionMiddleware

type VersionMiddleware struct {
	Version string
}

VersionMiddleware inserts the current version in all requests

func NewVersionMiddleware

func NewVersionMiddleware() *VersionMiddleware

NewVersionMiddleware with API version

func (*VersionMiddleware) Serve

Serve serves the middleware

Jump to

Keyboard shortcuts

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