web

package
v0.1.4-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInternalServerError is for when something bad happens internally.
	ErrInternalServerError = errors.New("internal server error")
)
View Source
var InvalidPageErr = NewBadRequestError("Invalid page parameter")

InvalidPageErr is for an invalid page / bad request.

Functions

func ErrorHandler

func ErrorHandler(err error, ctx echo.Context)

ErrorHandler logs errors to the logger if there are any and sends the appropriate response back.

func JSONDetailView

func JSONDetailView(ctx echo.Context, data interface{}, statusCode int) error

JSONDetailView returns a detail view.

func JSONDetailViewOK

func JSONDetailViewOK(ctx echo.Context, data interface{}) error

JSONDetailViewOK returns a detail view for 200 responses.

func JSONListViewOK

func JSONListViewOK(ctx echo.Context, data []interface{}, itemsPerPage int) error

JSONListViewOK returns a list view.

func JWTMiddlewareWithConfig

func JWTMiddlewareWithConfig(config JWTConfig) echo.MiddlewareFunc

JWTMiddlewareWithConfig creates a new middleware func from the specified configuration.

func NewBadRequestError

func NewBadRequestError(message string) *echo.HTTPError

NewBadRequestError creates a new HTTP error for a 304 status.

func NewDefaultJWTMiddleware

func NewDefaultJWTMiddleware() echo.MiddlewareFunc

NewDefaultJWTMiddleware creates the default JWT middleware with the default config.

func NewJSONErrorView

func NewJSONErrorView(ctx echo.Context, err string, statusCode int) error

NewJSONErrorView returns a new view JSON view with an error message and status code.

func NewNotFoundError

func NewNotFoundError(message string) *echo.HTTPError

NewNotFoundError creates a new HTTP error for a 404 status.

func ReferrerPolicyMiddleware

func ReferrerPolicyMiddleware(policy string) echo.MiddlewareFunc

ReferrerPolicyMiddleware sets the `Referrer-Policy` header for the specified policy.

func RequireCheapAuthentication

func RequireCheapAuthentication(next echo.HandlerFunc) echo.HandlerFunc

RequireCheapAuthentication is a cheap, temporary authentication middleware for handling requests.

Types

type App

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

App is the struct for the web app with echo and the controllers.

func NewApp

func NewApp(
	expandedSvc comic.ExpandedServicer,
	searcher search.Searcher,
	statsRepository comic.StatsRepository,
	rankedSvc comic.RankedServicer,
	ctr comic.CharacterThumbRepository) *App

NewApp creates a new app from the parameters.

func NewAppFactory

func NewAppFactory(db *pg.DB, redis *redis.Client) *App

NewAppFactory creates a new app with minimal dependencies.

func (*App) Close

func (a *App) Close() error

Close closes the app server.

func (App) Run

func (a App) Run(port string) error

Run runs the web application from the specified port. Logs and exits if there is an error.

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the application.

type Character

type Character struct {
	*comic.Character
	*comic.CharacterThumbnails
}

Character is a character with thumbnails attached.

func NewCharacter

func NewCharacter(c *comic.Character, th *comic.CharacterThumbnails) *Character

NewCharacter creates a new character for presentation.

func (*Character) MarshalJSON

func (c *Character) MarshalJSON() ([]byte, error)

MarshalJSON overrides JSON marshaling for presentation.

type CharacterController

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

CharacterController is the character controller.

func NewCharacterController

func NewCharacterController(eSvc comic.ExpandedServicer, rSvc comic.RankedServicer) *CharacterController

NewCharacterController creates a new character controller.

func (CharacterController) Character

func (c CharacterController) Character(ctx echo.Context) error

Character gets a character by its slug.

func (CharacterController) Characters

func (c CharacterController) Characters(ctx echo.Context) error

Characters lists the characters.

type DetailView

type DetailView struct {
	Meta `json:"meta"`
	Data interface{} `json:"data"`
}

DetailView is a detail view for a single object.

func NewDetailView

func NewDetailView(data interface{}, statusCode int) DetailView

NewDetailView returns a new detail view with a 200.

func NewDetailViewOK

func NewDetailViewOK(data interface{}) DetailView

NewDetailViewOK returns a new detail view with a 200.

type JWTConfig

type JWTConfig struct {
	SecretSigningKey string
}

JWTConfig is a struct for configuration.

func NewJWTConfigFromEnvironment

func NewJWTConfigFromEnvironment() JWTConfig

NewJWTConfigFromEnvironment creates a new configuration struct from environment variables.

type ListView

type ListView struct {
	Meta `json:"meta"`
	Data []interface{} `json:"data"`
}

ListView is a list view for multiple, similar objects.

func NewListViewOK

func NewListViewOK(data []interface{}, pagination *Pagination) ListView

NewListViewOK returns a new list view with 200.

type Meta

type Meta struct {
	StatusCode int         `json:"status_code"`
	Error      *string     `json:"error"`
	Pagination *Pagination `json:"pagination"`
}

Meta is the meta struct for an HTTP JSON response.

type Page

type Page struct {
	Number int    `json:"number"`
	Link   string `json:"link"`
}

Page represents a page number and link.

type Pagination

type Pagination struct {
	PerPage      int    `json:"per_page"`
	PreviousPage string `json:"previous_page"`
	CurrentPage  string `json:"current_page"`
	NextPage     string `json:"next_page"`
}

Pagination is a view that displays pagination info.

func CreatePagination

func CreatePagination(ctx echo.Context, data []interface{}, itemsPerPage int) (*Pagination, error)

CreatePagination creates a new pagination. TODO: clean this crap up.

type PublisherController

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

PublisherController is the controller for publishers.

func NewPublisherController

func NewPublisherController(s comic.RankedServicer) *PublisherController

NewPublisherController creates a new publisher controller.

func (PublisherController) DC

func (c PublisherController) DC(ctx echo.Context) error

DC gets the publisher's characters with their appearances.

func (PublisherController) Marvel

func (c PublisherController) Marvel(ctx echo.Context) error

Marvel gets the publisher's characters with their appearances.

type SearchController

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

SearchController is the controller for search.

func NewSearchController

func NewSearchController(searcher search.Searcher, ctr comic.CharacterThumbRepository) *SearchController

NewSearchController creates a new search controller.

func (SearchController) SearchCharacters

func (c SearchController) SearchCharacters(ctx echo.Context) error

SearchCharacters searches characters with the `query` parameter.

type StatsController

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

StatsController is the controller for stats about comic cruncher.

func NewStatsController

func NewStatsController(repository comic.StatsRepository) *StatsController

NewStatsController creates a new stats controller.

func (StatsController) Stats

func (c StatsController) Stats(ctx echo.Context) error

Stats shows the stats for comic cruncher.

type TrendingController

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

TrendingController is the controller for trending characters.

func NewTrendingController

func NewTrendingController(s comic.RankedServicer) *TrendingController

NewTrendingController creates a new trending controller.

func (*TrendingController) DC

func (c *TrendingController) DC(ctx echo.Context) error

DC gets the trending characters for DC.

func (*TrendingController) Marvel

func (c *TrendingController) Marvel(ctx echo.Context) error

Marvel gets the trending characters for Marvel.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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