Documentation ¶
Index ¶
- type Handler
- type HandlerFunction
- type Middleware
- type MiddlewareFunction
- type Option
- func OptionErrorWriter(writer io.Writer) Option
- func OptionExitOnError(exitOnError bool) Option
- func OptionFlagSet(flagSet flags.FlagSet) Option
- func OptionHelpHandler(handler Handler) Option
- func OptionInput(reader io.Reader) Option
- func OptionOutputWriter(writer io.Writer) Option
- func OptionShellPrompt(prompt string) 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) Flags(fn flags.FlagHandler)
- 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 StandardRouter
- func (rtr *StandardRouter) Define(fd flags.FlagDefiner)
- func (rtr *StandardRouter) Execute(writer ResponseWriter, request *Request) error
- func (rtr *StandardRouter) Flags(fn flags.FlagHandler)
- func (rtr *StandardRouter) Group(setup func(r Router)) Router
- func (rtr *StandardRouter) Handle(command string, handler Handler)
- func (rtr *StandardRouter) HandleFunction(command string, handerFunction HandlerFunction)
- func (rtr *StandardRouter) Match(args []string) (Handler, bool)
- func (rtr *StandardRouter) Middlewares() []Middleware
- func (rtr *StandardRouter) Mount(command string, router Router)
- func (rtr *StandardRouter) NotFound(handler Handler)
- func (rtr *StandardRouter) Route(command string, setup func(r Router)) Router
- func (rtr *StandardRouter) Routes() map[string]Handler
- func (rtr *StandardRouter) 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 OptionExitOnError ¶ added in v0.9.0
OptionExitOnError shell options allows the user to determine the shell behaviour.
When true, the shell will exit when a handler returns an error.
func OptionFlagSet ¶
OptionFlagSet shell option allows the user to set the FlagSet used by the shell.
func OptionHelpHandler ¶ added in v0.8.0
OptionHelpHandler shell option allows the user to set the HelpHandler used by the shell.
The HelpHandler will be executed whenever a handler returns the HelpRequested error.
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 // Flagset contains the flagset used to parse arguments. FlagSet flags.FlagSet // 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 the request sent by the shell and processed by the router and handlers.
func NewRequest ¶
NewRequest wraps NewRequestWithContext using context.Background.
func NewRequestWithContext ¶
func NewRequestWithContext(ctx context.Context, path, args []string, flagSet flags.FlagSet, routes Routes) *Request
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) FlagValues ¶
func (request *Request) FlagValues() flags.FlagValues
FlagValues returns the parsed flag values for the request flagset.
type ResponseWriter ¶
type ResponseWriter interface { // Close will close the output and error writers if the conform to io.WriteCloser. Close() error // 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 // Flags adds a FlagHandler that will add flags to the request FlagSet before // it attempts to match a command. Flags(flags.FlagHandler) // Group adds a new inline-router to the router stack. Group(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) // Route adds a new sub-router to the router stack, along the specified command path. Route(string, func(r Router)) Router // Mount adds the specified router to the router stack, along the specified command path. // // A mounted router will not inherit helper functions, such as the not found handler, // from the parent router in the same way a sub-router created by the Route() does, you must // set these manually. Mount(string, Router) // Use appends one or more middleware onto the router stack. Use(...Middleware) }
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) Flags ¶
func (shell *Shell) Flags(fn flags.FlagHandler)
Flags adds a FlagHandler that will add flags to the request FlagSet before it attempts to match a command.
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 StandardRouter ¶ added in v0.7.0
type StandardRouter struct {
// contains filtered or unexported fields
}
StandardRouter represents the standard implementation of the Router interface.
func (*StandardRouter) Define ¶ added in v0.7.0
func (rtr *StandardRouter) Define(fd flags.FlagDefiner)
Define allows the function to define command-line flags.
func (*StandardRouter) Execute ¶ added in v0.7.0
func (rtr *StandardRouter) Execute(writer ResponseWriter, request *Request) error
Execute is used to execute the shell handler.
func (*StandardRouter) Flags ¶ added in v0.7.0
func (rtr *StandardRouter) Flags(fn flags.FlagHandler)
Flags adds a FlagHandler that will add flags to the request FlagSet before it attempts to match a command.
func (*StandardRouter) Group ¶ added in v0.7.0
func (rtr *StandardRouter) Group(setup func(r Router)) Router
Group adds a new inline-router to the router stack.
func (*StandardRouter) Handle ¶ added in v0.7.0
func (rtr *StandardRouter) Handle(command string, handler Handler)
Handle adds a shell handler to the router stack, along the specified command path.
func (*StandardRouter) HandleFunction ¶ added in v0.7.0
func (rtr *StandardRouter) HandleFunction(command string, handerFunction HandlerFunction)
HandleFunction adds a shell handler function to the router stack, along the specified command path.
func (*StandardRouter) Match ¶ added in v0.7.0
func (rtr *StandardRouter) Match(args []string) (Handler, bool)
Match evaluates the routing tree for a handler that matches the supplied arguments and returns the handler, wrapped in the appropriate middleware handler functions
func (*StandardRouter) Middlewares ¶ added in v0.7.0
func (rtr *StandardRouter) Middlewares() []Middleware
Middlewares returns the list of middlewares in use by the router.
func (*StandardRouter) Mount ¶ added in v0.7.0
func (rtr *StandardRouter) Mount(command string, router Router)
Mount adds the specified router to the router stack, along the specified command path.
A mounted router will not inherit helper functions, such as the not found handler, from the parent router in the same way a sub-router created by the Route() does, you must set these manually.
func (*StandardRouter) NotFound ¶ added in v0.7.0
func (rtr *StandardRouter) NotFound(handler Handler)
NotFound defines a shell handler that will respond if a command path cannot be evaluated.
func (*StandardRouter) Route ¶ added in v0.7.0
func (rtr *StandardRouter) Route(command string, setup func(r Router)) Router
Route adds a new sub-router to the router stack, along the specified command path.
func (*StandardRouter) Routes ¶ added in v0.7.0
func (rtr *StandardRouter) Routes() map[string]Handler
Routes returns the linked shell handlers.
func (*StandardRouter) Use ¶ added in v0.7.0
func (rtr *StandardRouter) 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) Close ¶ added in v0.6.0
func (writer *WrapperWriter) Close() error
Close will close the output and error writers if the conform to io.WriteCloser.
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.