api

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2016 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VERSION = "0.9.10"

VERSION identifies Khan's current version

Functions

func ApplyForMembershipHandler

func ApplyForMembershipHandler(app *App) func(c *iris.Context)

ApplyForMembershipHandler is the handler responsible for applying for new memberships

func ApproveOrDenyMembershipApplicationHandler

func ApproveOrDenyMembershipApplicationHandler(app *App) func(c *iris.Context)

ApproveOrDenyMembershipApplicationHandler is the handler responsible for approving or denying a membership invitation

func ApproveOrDenyMembershipInvitationHandler

func ApproveOrDenyMembershipInvitationHandler(app *App) func(c *iris.Context)

ApproveOrDenyMembershipInvitationHandler is the handler responsible for approving or denying a membership invitation

func CreateClanHandler

func CreateClanHandler(app *App) func(c *iris.Context)

CreateClanHandler is the handler responsible for creating new clans

func CreateGameHandler

func CreateGameHandler(app *App) func(c *iris.Context)

CreateGameHandler is the handler responsible for creating new games

func CreateHookHandler

func CreateHookHandler(app *App) func(c *iris.Context)

CreateHookHandler is the handler responsible for creating new hooks

func CreatePlayerHandler

func CreatePlayerHandler(app *App) func(c *iris.Context)

CreatePlayerHandler is the handler responsible for creating new players

func DeleteMembershipHandler

func DeleteMembershipHandler(app *App) func(c *iris.Context)

DeleteMembershipHandler is the handler responsible for deleting a member

func FailWith

func FailWith(status int, message string, c *iris.Context)

FailWith fails with the specified message

func HealthCheckHandler

func HealthCheckHandler(app *App) func(c *iris.Context)

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

func InviteForMembershipHandler

func InviteForMembershipHandler(app *App) func(c *iris.Context)

InviteForMembershipHandler is the handler responsible for creating new memberships

func LeaveClanHandler

func LeaveClanHandler(app *App) func(c *iris.Context)

LeaveClanHandler is the handler responsible for changing the clan ownership when the owner leaves it

func ListClansHandler

func ListClansHandler(app *App) func(c *iris.Context)

ListClansHandler is the handler responsible for returning a list of all clans

func LoadJSONPayload

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

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

func NewHTTPFromCtx

func NewHTTPFromCtx(ctx *iris.Context) *raven.Http

NewHTTPFromCtx returns a new context for Raven

func NewLoggerMiddleware

func NewLoggerMiddleware(theLogger zap.Logger) iris.HandlerFunc

NewLoggerMiddleware returns the logger middleware

func PromoteOrDemoteMembershipHandler

func PromoteOrDemoteMembershipHandler(app *App, action string) func(c *iris.Context)

PromoteOrDemoteMembershipHandler is the handler responsible for promoting or demoting a member

func RemoveHookHandler

func RemoveHookHandler(app *App) func(c *iris.Context)

RemoveHookHandler is the handler responsible for removing existing hooks

func RetrieveClanHandler

func RetrieveClanHandler(app *App) func(c *iris.Context)

RetrieveClanHandler is the handler responsible for returning details for a given clan

func RetrieveClanSummaryHandler

func RetrieveClanSummaryHandler(app *App) func(c *iris.Context)

RetrieveClanSummaryHandler is the handler responsible for returning details summary for a given clan

func RetrieveClansSummariesHandler

func RetrieveClansSummariesHandler(app *App) func(c *iris.Context)

RetrieveClansSummariesHandler is the handler responsible for returning details summary for a given list of clans

func RetrievePlayerHandler

func RetrievePlayerHandler(app *App) func(c *iris.Context)

RetrievePlayerHandler is the handler responsible for returning details for a given player

func SearchClansHandler

func SearchClansHandler(app *App) func(c *iris.Context)

SearchClansHandler is the handler responsible for searching for clans

func StatusHandler

func StatusHandler(app *App) func(c *iris.Context)

StatusHandler is the handler responsible for reporting khan status

func SucceedWith

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

SucceedWith sends payload to user with status 200

func TransferOwnershipHandler

func TransferOwnershipHandler(app *App) func(c *iris.Context)

TransferOwnershipHandler is the handler responsible for transferring the clan ownership to another clan member

func UpdateClanHandler

func UpdateClanHandler(app *App) func(c *iris.Context)

UpdateClanHandler is the handler responsible for updating existing clans

func UpdateGameHandler

func UpdateGameHandler(app *App) func(c *iris.Context)

UpdateGameHandler is the handler responsible for updating existing

func UpdatePlayerHandler

func UpdatePlayerHandler(app *App) func(c *iris.Context)

UpdatePlayerHandler is the handler responsible for updating existing

Types

type App

type App struct {
	Debug          bool
	Port           int
	Host           string
	ConfigPath     string
	Errors         metrics.EWMA
	App            *iris.Framework
	Db             models.DB
	Config         *viper.Viper
	Dispatcher     *Dispatcher
	Logger         zap.Logger
	ReadBufferSize int
}

App is a struct that represents a Khan API Application

func GetApp

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

GetApp returns a new Khan API Application

func (*App) BeginTrans

func (app *App) BeginTrans(l zap.Logger) (*gorp.Transaction, error)

BeginTrans in the current Db connection

func (*App) Commit

func (app *App) Commit(tx *gorp.Transaction, msg string, l zap.Logger) error

Commit transaction

func (*App) Configure

func (app *App) Configure()

Configure instantiates the required dependencies for Khan Api Application

func (*App) DispatchHooks

func (app *App) DispatchHooks(gameID string, eventType int, payload map[string]interface{}) error

DispatchHooks dispatches web hooks for a specific game and event type

func (*App) GetCtxDB

func (app *App) GetCtxDB(ctx *iris.Context) (models.DB, error)

GetCtxDB returns the proper database connection depending on the request context

func (*App) GetGame

func (app *App) GetGame(gameID string) (*models.Game, error)

GetGame returns a game by Public ID

func (*App) GetHooks

func (app *App) GetHooks() map[string]map[int][]*models.Hook

GetHooks returns all available hooks

func (*App) Rollback

func (app *App) Rollback(tx *gorp.Transaction, msg string, l zap.Logger, err error) error

Rollback transaction

func (*App) Start

func (app *App) Start()

Start starts listening for web requests at specified host and port

type Dispatch

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

Dispatch represents an event hook to be sent to all available dispatchers

type Dispatcher

type Dispatcher struct {
	Jobs int
	// contains filtered or unexported fields
}

Dispatcher is responsible for sending web hooks to workers

func NewDispatcher

func NewDispatcher(app *App, workerCount, bufferSize int) (*Dispatcher, error)

NewDispatcher creates a new dispatcher available to our app

func (*Dispatcher) DispatchHook

func (d *Dispatcher) DispatchHook(gameID string, eventType int, payload map[string]interface{})

DispatchHook dispatches an event hook for eventType to gameID with the specified payload

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start "starts" the dispatcher

func (*Dispatcher) Wait

func (d *Dispatcher) Wait(timeout ...int)

Wait blocks until all jobs are done

type LoggerMiddleware

type LoggerMiddleware struct {
	Logger zap.Logger
}

LoggerMiddleware is responsible for logging to Zap all requests

func (*LoggerMiddleware) Serve

func (l *LoggerMiddleware) Serve(ctx *iris.Context)

Serve serves the middleware

type RecoveryMiddleware

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

RecoveryMiddleware recovers from errors in Iris

func (RecoveryMiddleware) Serve

func (r RecoveryMiddleware) Serve(ctx *iris.Context)

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 (*SentryMiddleware) Serve

func (l *SentryMiddleware) Serve(ctx *iris.Context)

Serve serves the middleware

type TransactionMiddleware

type TransactionMiddleware struct {
	App *App
}

TransactionMiddleware wraps transactions around the request

func (*TransactionMiddleware) Serve

func (m *TransactionMiddleware) Serve(c *iris.Context)

Serve Automatically wrap transaction around the request

type VersionMiddleware

type VersionMiddleware struct {
	App *App
}

VersionMiddleware automatically adds a version header to response

func (*VersionMiddleware) Serve

func (m *VersionMiddleware) Serve(c *iris.Context)

Serve automatically adds a version header to response

type Worker

type Worker struct {
	ID          int
	App         *App
	Dispatcher  *Dispatcher
	Work        chan Dispatch
	WorkerQueue chan chan Dispatch
}

Worker is an unit of work that keeps processing dispatches

func (*Worker) DispatchHook

func (w *Worker) DispatchHook(d Dispatch) error

DispatchHook dispatches web hooks for a specific game and event type

func (*Worker) Start

func (w *Worker) Start()

Start "starts" the worker by starting a goroutine, that is an infinite "for-select" loop.

Jump to

Keyboard shortcuts

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