daemon

package
v0.0.0-...-677ed08 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Unauthorized   = makeErrorResponder(http.StatusUnauthorized)
	NotFound       = makeErrorResponder(http.StatusNotFound)
	BadRequest     = makeErrorResponder(http.StatusBadRequest)
	BadMethod      = makeErrorResponder(http.StatusMethodNotAllowed)
	InternalError  = makeErrorResponder(http.StatusInternalServerError)
	NotImplemented = makeErrorResponder(http.StatusNotImplemented)
	Forbidden      = makeErrorResponder(http.StatusForbidden)
	Conflict       = makeErrorResponder(http.StatusConflict)
)

standard error responses

Functions

func UserFromRequest

func UserFromRequest(st *state.State, req *http.Request) (*auth.UserState, error)

UserFromRequest extracts user information from request and return the respective user in state, if valid It requires the state to be locked

Types

type Command

type Command struct {
	Path string
	//
	GET    ResponseFunc
	PUT    ResponseFunc
	POST   ResponseFunc
	DELETE ResponseFunc
	// can guest GET?
	GuestOK bool
	// can non-admin GET?
	UserOK bool
	// is this path accessible on the snapd-snap socket?
	SnapOK bool
	// contains filtered or unexported fields
}

A Command routes a request to an individual per-verb ResponseFUnc

func (*Command) ServeHTTP

func (c *Command) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Daemon

type Daemon struct {
	Version string
	// contains filtered or unexported fields
}

A Daemon listens for requests and routes them to the right command

func New

func New() (*Daemon, error)

New Daemon

func (*Daemon) Dying

func (d *Daemon) Dying() <-chan struct{}

Dying is a tomb-ish thing

func (*Daemon) Init

func (d *Daemon) Init() error

Init sets up the Daemon's internal workings. Don't call more than once.

func (*Daemon) Start

func (d *Daemon) Start()

Start the Daemon

func (*Daemon) Stop

func (d *Daemon) Stop() error

Stop shuts down the Daemon

type FileResponse

type FileResponse string

A FileResponse 's ServeHTTP method serves the file

func (FileResponse) ServeHTTP

func (f FileResponse) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP from the Response interface

type Meta

type Meta struct {
	Sources           []string `json:"sources,omitempty"`
	Paging            *Paging  `json:"paging,omitempty"`
	SuggestedCurrency string   `json:"suggested-currency,omitempty"`
	Change            string   `json:"change,omitempty"`
}

TODO This is being done in a rush to get the proper external

JSON representation in the API in time for the release.
The right code style takes a bit more work and unifies
these fields inside resp.

type Paging

type Paging struct {
	Page  int `json:"page"`
	Pages int `json:"pages"`
}

type Response

type Response interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Response knows how to serve itself, and how to find itself

func AssertResponse

func AssertResponse(asserts []asserts.Assertion, bundle bool) Response

AssertResponse builds a response whose ServerHTTP method serves one or a bundle of assertions.

func AsyncResponse

func AsyncResponse(result map[string]interface{}, meta *Meta) Response

AsyncResponse builds an "async" response from the given *Task

func EventResponse

func EventResponse(hub *notifications.Hub) Response

EventResponse returns a response whose ServerHTTP method creates a websocket connection used to communicate operation and logging notifications.

func SyncResponse

func SyncResponse(result interface{}, meta *Meta) Response

SyncResponse builds a "sync" response from the given result.

type ResponseFunc

type ResponseFunc func(*Command, *http.Request, *auth.UserState) Response

A ResponseFunc handles one of the individual verbs for a method

type ResponseType

type ResponseType string

ResponseType is the response type

const (
	ResponseTypeSync  ResponseType = "sync"
	ResponseTypeAsync ResponseType = "async"
	ResponseTypeError ResponseType = "error"
)

"there are three standard return types: Standard return value, Background operation, Error", each returning a JSON object with the following "type" field:

Jump to

Keyboard shortcuts

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