Documentation ¶
Index ¶
- func Register(name string, handler Handler) error
- func Tail(buffer *bytes.Buffer, n int) string
- type Decoder
- type Engine
- func (eng *Engine) HackGetGlobalVar(key string) interface{}
- func (eng *Engine) HackSetGlobalVar(key string, val interface{})
- func (eng *Engine) IsShutdown() bool
- func (eng *Engine) Job(name string, args ...string) *Job
- func (eng *Engine) OnShutdown(h func())
- func (eng *Engine) ParseJob(input string) (*Job, error)
- func (eng *Engine) Register(name string, handler Handler) error
- func (eng *Engine) RegisterCatchall(catchall Handler)
- func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (eng *Engine) Shutdown()
- func (eng *Engine) String() string
- type Env
- func (env *Env) Decode(src io.Reader) error
- func (env *Env) Encode(dst io.Writer) error
- func (env *Env) Exists(key string) bool
- func (env *Env) Get(key string) (value string)
- func (env *Env) GetBool(key string) (value bool)
- func (env *Env) GetInt(key string) int
- func (env *Env) GetInt64(key string) int64
- func (env *Env) GetJson(key string, iface interface{}) error
- func (env *Env) GetList(key string) []string
- func (env *Env) GetSubEnv(key string) *Env
- func (env *Env) GetTime(key string) (time.Time, error)
- func (env *Env) Import(src interface{}) (err error)
- func (env *Env) Init(src *Env)
- func (env *Env) InitMultiMap(m map[string][]string)
- func (env *Env) Len() int
- func (env *Env) Map() map[string]string
- func (env *Env) MultiMap() map[string][]string
- func (env *Env) Set(key, value string)
- func (env *Env) SetAuto(k string, v interface{})
- func (env *Env) SetBool(key string, value bool)
- func (env *Env) SetInt(key string, value int)
- func (env *Env) SetInt64(key string, value int64)
- func (env *Env) SetJson(key string, value interface{}) error
- func (env *Env) SetList(key string, value []string) error
- func (env *Env) SetSubEnv(key string, sub *Env) error
- func (env *Env) SetTime(key string, t time.Time)
- func (env *Env) WriteTo(dst io.Writer) (int64, error)
- type Hack
- type Handler
- type Input
- type Installer
- type Job
- func (job *Job) CallString() string
- func (job *Job) Cancel()
- func (job *Job) DecodeEnv(src io.Reader) error
- func (job *Job) EncodeEnv(dst io.Writer) error
- func (job *Job) Env() *Env
- func (job *Job) EnvExists(key string) (value bool)
- func (job *Job) Environ() map[string]string
- func (job *Job) Errorf(format string, args ...interface{}) (n int, err error)
- func (job *Job) Getenv(key string) (value string)
- func (job *Job) GetenvBool(key string) (value bool)
- func (job *Job) GetenvInt(key string) int
- func (job *Job) GetenvInt64(key string) int64
- func (job *Job) GetenvJson(key string, iface interface{}) error
- func (job *Job) GetenvList(key string) []string
- func (job *Job) GetenvSubEnv(key string) *Env
- func (job *Job) GetenvTime(key string) (value time.Time, err error)
- func (job *Job) ImportEnv(src interface{}) (err error)
- func (job *Job) Printf(format string, args ...interface{}) (n int, err error)
- func (job *Job) Run() (err error)
- func (job *Job) SetCloseIO(val bool)
- func (job *Job) Setenv(key, value string)
- func (job *Job) SetenvBool(key string, value bool)
- func (job *Job) SetenvInt(key string, value int)
- func (job *Job) SetenvInt64(key string, value int64)
- func (job *Job) SetenvJson(key string, value interface{}) error
- func (job *Job) SetenvList(key string, value []string) error
- func (job *Job) SetenvSubEnv(key string, value *Env) error
- func (job *Job) SetenvTime(key string, value time.Time)
- func (job *Job) WaitCancelled() <-chan struct{}
- type Output
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Decoder ¶
func NewDecoder ¶
type Engine ¶
type Engine struct { Stdout io.Writer Stderr io.Writer Stdin io.Reader Logging bool // contains filtered or unexported fields }
The Engine is the core of Docker. It acts as a store for *containers*, and allows manipulation of these containers by executing *jobs*.
func (*Engine) HackGetGlobalVar ¶
func (*Engine) HackSetGlobalVar ¶
func (*Engine) IsShutdown ¶
IsShutdown returns true if the engine is in the process of shutting down, or already shut down. Otherwise it returns false.
func (*Engine) Job ¶
Job creates a new job which can later be executed. This function mimics `Command` from the standard os/exec package.
func (*Engine) OnShutdown ¶
func (eng *Engine) OnShutdown(h func())
OnShutdown registers a new callback to be called by Shutdown. This is typically used by services to perform cleanup.
func (*Engine) ParseJob ¶
ParseJob creates a new job from a text description using a shell-like syntax.
The following syntax is used to parse `input`:
* Words are separated using standard whitespaces as separators. * Quotes and backslashes are not interpreted. * Words of the form 'KEY=[VALUE]' are added to the job environment. * All other words are added to the job arguments.
For example:
job, _ := eng.ParseJob("VERBOSE=1 echo hello TEST=true world")
The resulting job will have:
job.Args={"echo", "hello", "world"} job.Env={"VERBOSE":"1", "TEST":"true"}
func (*Engine) RegisterCatchall ¶
func (*Engine) ServeHTTP ¶
func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP executes a job as specified by the http request `r`, and sends the result as an http response. This method allows an Engine instance to be passed as a standard http.Handler interface.
Note that the protocol used in this method is a convenience wrapper and is not the canonical implementation of remote job execution. This is because HTTP/1 does not handle stream multiplexing, and so cannot differentiate stdout from stderr. Additionally, headers cannot be added to a response once data has been written to the body, which makes it inconvenient to return metadata such as the exit status.
func (*Engine) Shutdown ¶
func (eng *Engine) Shutdown()
Shutdown permanently shuts down eng as follows:
- It refuses all new jobs, permanently.
- It waits for all active jobs to complete (with no timeout)
- It calls all shutdown handlers concurrently (if any)
- It returns when all handlers complete, or after 15 seconds, whichever happens first.
type Env ¶
type Env []string
func (*Env) Decode ¶
DecodeEnv decodes `src` as a json dictionary, and adds each decoded key-value pair to the environment.
If `src` cannot be decoded as a json dictionary, an error is returned.
func (*Env) Get ¶
Get returns the last value associated with the given key. If there are no values associated with the key, Get returns the empty string.
func (*Env) InitMultiMap ¶
InitMultiMap removes all values in env, then initializes new values from the contents of m.
func (*Env) Len ¶
Len returns the number of keys in the environment. Note that len(env) might be different from env.Len(), because the same key might be set multiple times.
type Input ¶
func NewInput ¶
func NewInput() *Input
NewInput returns a new Input object with no source attached. Reading to an empty Input will return io.EOF.
type Installer ¶
Installer is a standard interface for objects which can "install" themselves on an engine by registering handlers. This can be used as an entrypoint for external plugins etc.
type Job ¶
type Job struct { Eng *Engine Name string Args []string Stdout *Output Stderr *Output Stdin *Input // contains filtered or unexported fields }
A job is the fundamental unit of work in the docker engine. Everything docker can do should eventually be exposed as a job. For example: execute a process in a container, create a new container, download an archive from the internet, serve the http api, etc.
The job API is designed after unix processes: a job has a name, arguments, environment variables, standard streams for input, output and error.
func (*Job) CallString ¶
func (*Job) Cancel ¶
func (job *Job) Cancel()
When called, causes the Job.WaitCancelled channel to unblock.
func (*Job) DecodeEnv ¶
DecodeEnv decodes `src` as a json dictionary, and adds each decoded key-value pair to the environment.
If `src` cannot be decoded as a json dictionary, an error is returned.
func (*Job) GetenvBool ¶
func (*Job) GetenvInt64 ¶
func (*Job) GetenvJson ¶
func (*Job) GetenvList ¶
Returns nil if key not found
func (*Job) GetenvSubEnv ¶
func (*Job) Run ¶
Run executes the job and blocks until the job completes. If the job fails it returns an error
func (*Job) SetCloseIO ¶
func (*Job) SetenvBool ¶
func (*Job) SetenvInt64 ¶
func (*Job) SetenvJson ¶
func (*Job) WaitCancelled ¶
func (job *Job) WaitCancelled() <-chan struct{}
Returns a channel which is closed ("never blocks") when the job is cancelled.
type Output ¶
func NewOutput ¶
func NewOutput() *Output
NewOutput returns a new Output object with no destinations attached. Writing to an empty Output will cause the written data to be discarded.
func (*Output) Add ¶
Add attaches a new destination to the Output. Any data subsequently written to the output will be written to the new destination in addition to all the others. This method is thread-safe.
func (*Output) AddEnv ¶
AddEnv starts a new goroutine which will decode all subsequent data as a stream of json-encoded objects, and point `dst` to the last decoded object. The result `env` can be queried using the type-neutral Env interface. It is not safe to query `env` until the Output is closed.
func (*Output) AddPipe ¶
AddPipe creates an in-memory pipe with io.Pipe(), adds its writing end as a destination, and returns its reading end for consumption by the caller. This is a rough equivalent similar to Cmd.StdoutPipe() in the standard os/exec package. This method is thread-safe.
func (*Output) Close ¶
Close unregisters all destinations and waits for all background AddTail and AddString tasks to complete. The Close method of each destination is called if it exists.
func (*Output) Set ¶
Set closes and remove existing destination and then attaches a new destination to the Output. Any data subsequently written to the output will be written to the new destination in addition to all the others. This method is thread-safe.