app

package
v0.0.0-...-a512109 Latest Latest
Warning

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

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

Documentation

Overview

Package app defines the different pieces of the application, which are all put together in main.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Config returns an *oauth2.Config configured to reach a OAuth provider.
	Config() *oauth2.Config
}

Client is an interface which provides access to a specific OAuth-based provider.

func NewClient

func NewClient(config *oauth2.Config) Client

NewClient creates an app.Client which stores and returns a previously built *oauth2.Config.

type Error

type Error struct {
	Message string
	Status  int
}

Error represents an error in processing, which will be returned from an app.Handler and converted into the appropriate HTTP status code and message.

func Wrap

func Wrap(err error, status int) *Error

Wrap builds an app.Error from an error and status code. If err is nil or an *app.Error, it will be returned unmodified.

func (*Error) Error

func (err *Error) Error() string

Error implements the error interface.

type Handler

type Handler func(w http.ResponseWriter, r *http.Request) *Error

Handler is an http.Handler which runs the given function and sends the data in *Error, if any, to http.Error, with the proper status code.

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type Router

type Router interface {
	// Route builds an endpoint to the given path.
	Route(path string) string

	// Books returns the endpoint which retrieves the user's books.
	Books() string

	// Connect returns an endpoint which starts the OAuth flow to authorize this app.
	Connect() string

	// Disconnect returns an endpoint which revoke's this application's access to the user's data.
	Disconnect() string

	// OAuthCallback returns an endpoint which will be called by the OAuth provider to end the OAuth flow.
	OAuthCallback() string
}

Router is an interface used to determine the endpoints which will be routed to an app.Service's methods.

func NewRouter

func NewRouter(pathPrefix string) Router

NewRouter creates a new app.Router which uses pre-determined routes for every method, prefixed by a given path.

type Service

type Service interface {
	// HandleBooks lists the user's books. Works only if the user was previously authenticated and authorized with
	// HandleConnect.
	HandleBooks(w http.ResponseWriter, r *http.Request) *Error

	// HandleConnect starts the OAuth flow, redirecting to the provider. The provider's response should be answered by
	// HandleOAuthCallback.
	HandleConnect(w http.ResponseWriter, r *http.Request) *Error

	// HandleDisconnect revokes this application's access to the user's data.
	HandleDisconnect(w http.ResponseWriter, r *http.Request) *Error

	// HandleOAuthCallback should be called by the OAuth provider with its answer to the auth attempt started in
	// HandleConnect.
	HandleOAuthCallback(w http.ResponseWriter, r *http.Request) *Error
}

Service is an interface which provides app.Handler-compatible methods, which will handle user requests.

func NewService

func NewService() Service

NewService creates a default app.Service with empty implementations.

Jump to

Keyboard shortcuts

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