Documentation
¶
Index ¶
- type Handler
- type HandlerFunction
- type Middleware
- type MiddlewareFunction
- type Option
- type OptionFunction
- type Request
- type ResponseWriter
- type Router
- type Routes
- type Shell
- func (shell *Shell) Closed() chan struct{}
- func (shell *Shell) Execute(ctx context.Context) error
- func (shell *Shell) Group(fn func(r Router)) Router
- func (shell *Shell) Handle(command string, handler Handler)
- func (shell *Shell) HandleFunction(command string, fn HandlerFunction)
- func (shell *Shell) NotFound(handler Handler)
- func (shell *Shell) Options(options ...Option) error
- func (shell *Shell) Route(command string, fn func(r Router)) Router
- func (shell *Shell) Start(ctx context.Context) error
- func (shell *Shell) Use(middleware ...Middleware)
- type WrapperWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface { // Execute is used to execute the shell handler. Execute(ResponseWriter, *Request) error }
The Handler interface describes a shell handler functions.
type HandlerFunction ¶
type HandlerFunction func(ResponseWriter, *Request) error
The HandlerFunction type is an adapter to allow the use of ordinary functions as shell handlers.
func (HandlerFunction) Execute ¶
func (fn HandlerFunction) Execute(writer ResponseWriter, request *Request) error
Execute is used to execute the shell handler function.
type Middleware ¶
type Middleware interface { // Handle is used to perform the middleware function. Handle(next Handler) Handler }
The Middleware interface describes a shell middleware function
type MiddlewareFunction ¶
The MiddlewareFunction type is an adapter to allow the use of ordinary functions as shell middleware.
func (MiddlewareFunction) Handle ¶
func (middleware MiddlewareFunction) Handle(next Handler) Handler
Handle is used to perform the middleware function.
type Option ¶
The Option interface describes a shell option function
func OptionErrorWriter ¶
OptionErrorWriter shell option allows the user to set the shell error writer.
func OptionInput ¶
OptionInput shell option allows the user to set the shell input reader.
func OptionOutputWriter ¶
OptionOutputWriter shell option allows the user to set the shell output writer.
func OptionShellPrompt ¶
OptionShellPrompt shell option allows the user to set the basic shell prompt message.
type OptionFunction ¶
The OptionFunction type is an adapter to allow the use of ordinary functions as shell options.
func (OptionFunction) Apply ¶
func (option OptionFunction) Apply(shell *Shell) error
Apply is used to apply the shell options.
type Request ¶
type Request struct { // Args contains the arguments passed as part of the request. Args []string // Path contains the request path. Path []string // Routes contains the router routes functions linked to the executed router. Routes Routes // contains filtered or unexported fields }
A Request represents a the request sent by the shell and processed by the router and handlers.
func NewRequest ¶
NewRequest wraps NewRequestWithContext using context.Background.
func NewRequestWithContext ¶
NewRequestWithContext returns a new Request given a path, args, and routes.
func (*Request) Context ¶
Context returns the request's context. To change the context, use WithContext.
func (*Request) WithContext ¶
WithContext returns a shallow copy of the request with its context changed to ctx.
type ResponseWriter ¶
type ResponseWriter interface { // ErrorWriter returns an io.Writer used for the error output ErrorWriter() io.Writer // Write byte array to the output writer. Write([]byte) (int, error) // WriteError will write byte array to the error writer. WriteError([]byte) (int, error) }
ResponseWriter is an interface is used by an shell handler to construct a response.
type Router ¶
type Router interface { Handler Routes // Use appends one or more middleware onto the router stack. Use(...Middleware) // Group adds a new inline-router to the router stack. Group(func(r Router)) Router // Route adds a new sub-router to the router stack, along the specified command path. Route(string, func(r Router)) Router // Handle adds a shell handler to the router stack, along the specified command path. Handle(string, Handler) // HandleFunction adds a shell handler function to the router stack, along the specified command path. HandleFunction(string, HandlerFunction) // NotFound defines a shell handler that will respond if a command path cannot be evaluated. NotFound(Handler) }
The Router interface details the core shell router functions.
type Routes ¶
type Routes interface { // Routes returns the linked shell handlers. Routes() map[string]Handler // Middlewares returns the list of middlewares in use by the router. Middlewares() []Middleware // Match evaluates the routing tree for a handler that matches the supplied arguments // and returns the handler, wrapped in the appropriate middleware handler functions Match([]string) (Handler, bool) }
Routes interface describes functions for router traversal.
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell exposes the command-line or interactive shell functionality.
The shell can be execute as a command-line tool by using the Execute function or to be run as an interactive shell using the Start function
func (*Shell) Closed ¶
func (shell *Shell) Closed() chan struct{}
Closed is used to determine if the shell session is closed.
func (*Shell) Execute ¶
Execute is used to execute the shell, using os.Args to evaluate which function to execute.
func (*Shell) Handle ¶
Handle adds a shell handler to the router stack, along the specified command path.
func (*Shell) HandleFunction ¶
func (shell *Shell) HandleFunction(command string, fn HandlerFunction)
HandleFunction adds a shell handler function to the router stack, along the specified command path.
func (*Shell) NotFound ¶
NotFound defines a shell handler that will respond if a command path cannot be evaluated.
func (*Shell) Options ¶
Options will apply the supplied options to the shell.
Options should be called before adding middleware, groups, or handlers.
func (*Shell) Route ¶
Route adds a new sub-router to the router stack, along the specified command path.
func (*Shell) Start ¶
Start is used to begin a new shell session.
The interactive shell will read input and evaluate the commands to execute handler functions.
func (*Shell) Use ¶
func (shell *Shell) Use(middleware ...Middleware)
Use appends one or more middleware onto the router stack.
type WrapperWriter ¶
type WrapperWriter struct {
// contains filtered or unexported fields
}
The WrapperWriter is used as a simple ResponseWritter
func NewWrapperWriter ¶
func NewWrapperWriter(ctx context.Context, outputWritter io.Writer, errorWriter io.Writer) *WrapperWriter
NewWrapperWriter returns a new WrapperWriter using the specified output and error writers.
func (*WrapperWriter) ErrorWriter ¶
func (writer *WrapperWriter) ErrorWriter() io.Writer
ErrorWriter returns an io.Writer used for the error output
func (*WrapperWriter) Write ¶
func (writer *WrapperWriter) Write(bytes []byte) (int, error)
Write byte array to the output writer.
func (*WrapperWriter) WriteError ¶
func (writer *WrapperWriter) WriteError(bytes []byte) (int, error)
WriteError will write byte array to the error writer.