fire

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2016 License: MIT Imports: 14 Imported by: 1

README

Logo

Go on Fire

Build Status Coverage Status GoDoc Release Go Report Card

An idiomatic Go framework for building Ember.js compatible APIs.

Go on Fire is built on top of the powerful echo HTTP routing and server framework, implements the JSON API specification through the dedicated jsonapi library, uses the very stable mgo MongoDB driver for persisting resources and leverages the fosite library to provide out of the box support for OAuth2.

The deliberate and tight integration of these components provides a very simple and extensible set of abstractions for rapidly building backend services for websites that use Ember.js as their frontend framework. Of course it can also be used in conjunction with any other single page application framework or as a backend for native mobile applications.

An example application that uses Go on Fire to build an OAuth2 secured JSON API that is consumed by an Ember Application can be found here: github.com/gonfire/example.

To quickly get started with building an API with Go on Fire follow the quickstart guide, read the detailed sections in this documentation and refer to the Package documentation for more detailed information on the used types and methods.

License

The MIT License (MIT)

Copyright (c) 2016 Joël Gähwiler

Documentation

Overview

Package fire implements a small and opinionated framework for Go providing Ember compatible JSON APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

An Application provides a simple way to combine multiple components.

func New

func New() *Application

New creates and returns a new Application.

func (*Application) Components

func (a *Application) Components() []Component

Components will return all so far registered components.

func (*Application) Exec

func (a *Application) Exec(fn func() error)

Exec will execute the passed function and report any potential errors.

See: Report.

func (*Application) Mount

func (a *Application) Mount(component Component)

Mount will mount the passed Component in the application.

Note: Each component should only be mounted once before calling Run or Start.

func (*Application) Report

func (a *Application) Report(err error)

Report will report the passed error using all mounted reporter components.

Note: If a reporter fails to report an occurring error, the current goroutine will panic and print the original error and the reporter's error.

func (*Application) Router

func (a *Application) Router() *echo.Echo

Router returns the used echo router for this application.

func (*Application) Start

func (a *Application) Start(addr string)

Start will start the application using a new server listening on the specified address.

See StartWith.

func (*Application) StartSecure

func (a *Application) StartSecure(addr, certFile, keyFile string)

StartSecure will start the application with a new server listening on the specified address using the provided TLS certificate.

See StartWith.

func (*Application) StartWith

func (a *Application) StartWith(server engine.Server)

StartWith will start the application using the specified server.

Note: Any errors that occur during the boot process of the application and later during request processing are reported using the registered reporters. If there are no reporters or one of the reporter fails to report the error, the calling goroutine will panic and print the error (see Exec).

func (*Application) Stop

func (a *Application) Stop()

Stop will stop a running application and wait until it has been properly stopped.

func (*Application) Yield

func (a *Application) Yield()

Yield will block the calling goroutine until the the application has been stopped. It will automatically stop the application if the process receives the SIGINT signal.

type BootableComponent

type BootableComponent interface {
	Component

	// Setup will be called before the applications starts and allows further
	// initialization.
	Setup() error

	// Teardown will be called after applications has stopped and allows proper
	// cleanup.
	Teardown() error
}

A BootableComponent is an extended component with additional methods for setup and teardown.

type Component

type Component interface {
	// Describe must return a ComponentInfo struct that describes the component.
	Describe() ComponentInfo
}

A Component that can be mounted in an application.

type ComponentInfo

type ComponentInfo struct {
	// The name of the component.
	Name string

	// The settings it is using.
	Settings Map
}

A ComponentInfo is returned by a component to describe itself.

type Inspector

type Inspector struct {
	Writer io.Writer
}

An Inspector can be used during development to print the applications component stack, the route table and log requests to writer.

func DefaultInspector

func DefaultInspector() *Inspector

DefaultInspector creates and returns a new inspector that writes to stdout.

func NewInspector

func NewInspector(writer io.Writer) *Inspector

NewInspector creates and returns a new inspector.

func (*Inspector) Before

func (i *Inspector) Before(stage Phase, app *Application)

Before implements the InspectorComponent interface.

func (*Inspector) Describe

func (i *Inspector) Describe() ComponentInfo

Describe implements the Component interface.

func (*Inspector) Register

func (i *Inspector) Register(router *echo.Echo)

Register implements the RoutableComponent interface.

func (*Inspector) Report

func (i *Inspector) Report(err error) error

Report implements the ReporterComponent interface.

type InspectorComponent

type InspectorComponent interface {
	Component

	// Before is called by the application before the specified phase is
	// initiated by the passed application.
	Before(phase Phase, app *Application)
}

An InspectorComponent is an extended component that is able to inspect the boot process of an application and inspect all used components and the router instance.

type Map

type Map map[string]interface{}

Map is a general purpose map used for configuration.

type Phase

type Phase int

A Phase is used in conjunction with a InspectorComponent and denotes a phase the application will undergo.

const (
	// Registration is the phase in which components get registered.
	Registration Phase = iota

	// Setup is the phase in which components get set up.
	Setup

	// Run is the phase in which the application handles requests.
	Run

	// Teardown is the phase in which components get teared down.
	Teardown

	// Termination is the phase in which the applications is terminated.
	Termination
)

func (Phase) String

func (p Phase) String() string

String returns the string representation of the phase.

type Reporter

type Reporter struct {
	Writer io.Writer
}

A Reporter can be used write errors occurring during request to a writer.

func DefaultReporter

func DefaultReporter() *Reporter

DefaultReporter creates and returns a reporter that writes errors to stderr.

func NewReporter

func NewReporter(writer io.Writer) *Reporter

NewReporter create and returns a new reporter writing to the specified writer.

func (*Reporter) Describe

func (r *Reporter) Describe() ComponentInfo

Describe implements the Component interface.

func (*Reporter) Report

func (r *Reporter) Report(err error) error

Report implements the ReporterComponent interface.

type ReporterComponent

type ReporterComponent interface {
	Component

	// Report is called by the application on every occurring error.
	Report(err error) error
}

A ReporterComponent is an extended component that is responsible for reporting errors.

type RoutableComponent

type RoutableComponent interface {
	Component

	// Register will be called by the application with a new echo router.
	Register(router *echo.Echo)
}

A RoutableComponent is a component that accepts requests from a router for routes that haven been registered using Register().

Directories

Path Synopsis
Package components contains additional components which can be mounted in a fire application.
Package components contains additional components which can be mounted in a fire application.
Package jsonapi implements components to build JSON APIs with fire.
Package jsonapi implements components to build JSON APIs with fire.
Package model implements a basic model abstraction for structs.
Package model implements a basic model abstraction for structs.
Package oauth2 implements an authenticator component that provides OAuth2 compatible authentication.
Package oauth2 implements an authenticator component that provides OAuth2 compatible authentication.

Jump to

Keyboard shortcuts

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