Documentation ¶
Index ¶
Constants ¶
const ( TaskRunning = "running" TaskSucceeded = "succeeded" TaskFailed = "failed" )
A task can be in one of three states
Variables ¶
var ( NotFound = makeErrorResponder(http.StatusNotFound) BadRequest = makeErrorResponder(http.StatusBadRequest) BadMethod = makeErrorResponder(http.StatusMethodNotAllowed) InternalError = makeErrorResponder(http.StatusInternalServerError) NotImplemented = makeErrorResponder(http.StatusNotImplemented) Forbidden = makeErrorResponder(http.StatusForbidden) )
standard error responses
Functions ¶
func FormatTime ¶
FormatTime outputs the given time in RFC3339 format to µs precision.
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 // contains filtered or unexported fields }
A Command routes a request to an individual per-verb ResponseFUnc
type Daemon ¶
type Daemon struct { sync.RWMutex // for concurrent access to the tasks map // contains filtered or unexported fields }
A Daemon listens for requests and routes them to the right command
func (*Daemon) DeleteTask ¶
DeleteTask removes a task from the tasks map, by uuid.
type FileResponse ¶
type FileResponse string
A FileResponse 's ServeHTTP method serves the file
func (FileResponse) Self ¶
func (f FileResponse) Self(*Command, *http.Request) Response
Self from the Response interface
func (FileResponse) ServeHTTP ¶
func (f FileResponse) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP from the Response interface
type Response ¶
type Response interface { ServeHTTP(w http.ResponseWriter, r *http.Request) Self(*Command, *http.Request) Response // has the same arity as ResponseFunc for convenience }
Response knows how to serve itself, and how to find itself
func AssertResponse ¶
AssertResponse builds a response whose ServerHTTP method serves one or a bundle of assertions.
func AsyncResponse ¶
AsyncResponse builds an "async" response from the given *Task
func SyncResponse ¶
func SyncResponse(result interface{}) Response
SyncResponse builds a "sync" response from the given result.
type ResponseFunc ¶
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:
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
A Task encapsulates an asynchronous operation.
func RunTask ¶
func RunTask(f func() interface{}) *Task
RunTask creates a Task for the given function and runs it.
func (*Task) Location ¶
Location of the task, based on the given route.
If the route can't build a URL for this task, returns the empty string.
func (*Task) Map ¶
Map the task onto a map[string]interface{}, using the given route for the Location()