Documentation
¶
Overview ¶
Package cmdutil provides abstractions for building things which can be started and stopped as a part of a executable's process lifecycle.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
Server runs synchronously and returns any errors. The Run method is expected to block until finished, returning any error, or until Stop is called. used with oklog/run.Group, where the first Server.Run to return will cancel the Group (regardless of the error returned). Use NewContextServer to create a Server that can block on a Context until Stop is called.
TODO[freeformz]: Document why Stop takes an error and what to do with is.
func MultiServer ¶
MultiServer which, when Run, will run all of the servers until one of them returns or is itself Stopped.
Example ¶
s := MultiServer(
ServerFunc(
func() error {
fmt.Println("A")
return nil
}),
)
if err := s.Run(); err != nil {
panic(err)
}
Output: A
Example (Stop) ¶
done := make(chan struct{})
s := MultiServer(
ServerFuncs{
RunFunc: func() error {
fmt.Println("A")
<-done
fmt.Println("B")
return nil
},
StopFunc: func(err error) {
fmt.Println(err)
close(done)
},
},
)
go func() {
time.Sleep(1 * time.Second)
s.Stop(io.EOF)
}()
if err := s.Run(); err != nil && err != context.Canceled {
panic(err)
}
Output: A context canceled B
func NewContextServer ¶
NewContextServer that when Run(), calls the given function with a context that is canceled when Stop() is called.
Example ¶
s := NewContextServer(
func(ctx context.Context) error {
// do something that doesn't block ex:
fmt.Println("A")
<-ctx.Done() // block waiting for context to be canceled
// can do any cleanup after this, or just return nil
// return cleanup()
return nil
},
)
var exitFast Server = ServerFunc(
// doesn't do anything, just returns
func() error {
return nil
},
)
var g run.Group
g.Add(s.Run, s.Stop)
g.Add(exitFast.Run, exitFast.Stop)
if err := g.Run(); err != nil {
panic(err)
}
Output: A
type ServerFunc ¶
type ServerFunc func() error
ServerFunc adapts a function to the Server interface. This is useful to adapt a closure to being a Server.
Example ¶
var a Server = ServerFunc(
func() error {
fmt.Println("A")
return nil
},
)
var g run.Group
g.Add(a.Run, a.Stop)
if err := g.Run(); err != nil {
panic(err)
}
Output: A
func (ServerFunc) Stop ¶
func (fn ServerFunc) Stop(error)
Stop is a noop for gradual compatibility with oklog run.Group.
type ServerFuncs ¶
ServerFuncs adapts two functions, one for Run, one for Stop, to the Server interface. This is useful for adapting closures so they can be used as a Server.
Example ¶
var a Server = ServerFuncs{
RunFunc: func() error {
_, err := fmt.Println("A")
return err
},
StopFunc: func(error) {},
}
var g run.Group
g.Add(a.Run, a.Stop)
if err := g.Run(); err != nil {
panic(err)
}
Output: A
Directories
¶
| Path | Synopsis |
|---|---|
|
Package debug wraps the gops agent for use as a cmdutil-compatible Server.
|
Package debug wraps the gops agent for use as a cmdutil-compatible Server. |
|
Package health provides cmdutil-compatible healthcheck utilities.
|
Package health provides cmdutil-compatible healthcheck utilities. |
|
Package https provides utilities for configuring and running HTTP servers over TLS.
|
Package https provides utilities for configuring and running HTTP servers over TLS. |
|
Package hypercmd provides utilities for creating "hyper commands", where multiple commands are bundled into a single executable to get faster builds and smaller binaries.
|
Package hypercmd provides utilities for creating "hyper commands", where multiple commands are bundled into a single executable to get faster builds and smaller binaries. |
|
Package metrics provides helpers for setting up metrics reporting.
|
Package metrics provides helpers for setting up metrics reporting. |
|
Package redispool supports setting up redis connection pools parameterized via environment variables.
|
Package redispool supports setting up redis connection pools parameterized via environment variables. |
|
Package rollbar provides helpers for setting up rollbar error reporting.
|
Package rollbar provides helpers for setting up rollbar error reporting. |
|
Package service provides standardized command and HTTP setup by smartly composing the other cmdutil packages based on environment variables.
|
Package service provides standardized command and HTTP setup by smartly composing the other cmdutil packages based on environment variables. |
|
Package signals provides a signal handler which is usable as a cmdutil.Server.
|
Package signals provides a signal handler which is usable as a cmdutil.Server. |
|
Package spaceca provides helpers for setting up TLS from a CA configuration.
|
Package spaceca provides helpers for setting up TLS from a CA configuration. |
|
Package svclog provides logging facilities for standard services.
|
Package svclog provides logging facilities for standard services. |