Documentation ¶
Index ¶
Constants ¶
const ( TaskRunning = "running" TaskSucceeded = "succeeded" TaskFailed = "failed" )
A task can be in one of three states
Variables ¶
var ( NotFound = ErrorResponse(http.StatusNotFound) BadRequest = ErrorResponse(http.StatusBadRequest) BadMethod = ErrorResponse(http.StatusMethodNotAllowed) InternalError = ErrorResponse(http.StatusInternalServerError) NotImplemented = ErrorResponse(http.StatusNotImplemented) Forbidden = ErrorResponse(http.StatusForbidden) )
standard error responses
Functions ¶
func FormatTime ¶
FormatTime outputs the given time as microseconds since the epoch UTC, formatted as a decimal string
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 ErrorResponseFunc ¶
ErrorResponseFunc is a callable error Response. So you can return e.g. InternalError, or InternalError(err, "something broke"), etc.
func ErrorResponse ¶
func ErrorResponse(status int) ErrorResponseFunc
ErrorResponse builds an "error" response from the given error status.
func (ErrorResponseFunc) Self ¶
func (f ErrorResponseFunc) Self(*Command, *http.Request) Response
Self returns (a copy of) this same response; mostly for convenience.
func (ErrorResponseFunc) ServeHTTP ¶
func (f ErrorResponseFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
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 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()