Documentation ¶
Index ¶
- type ConfigFileHandler
- type ConfigFileHandlerOption
- func WithAppendCommandDirHandlerOptions(options ...command_dir.CommandDirHandlerOption) ConfigFileHandlerOption
- func WithAppendTemplateDirHandlerOptions(options ...template_dir.TemplateDirHandlerOption) ConfigFileHandlerOption
- func WithAppendTemplateHandlerOptions(options ...template.TemplateHandlerOption) ConfigFileHandlerOption
- func WithConfigFileLocation(location string) ConfigFileHandlerOption
- func WithDevMode(devMode bool) ConfigFileHandlerOption
- func WithRepositoryFactory(rf RepositoryFactory) ConfigFileHandlerOption
- type ErrNoRepositoryFactory
- type RepositoryFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigFileHandler ¶
type ConfigFileHandler struct { Config *config.Config RepositoryFactory RepositoryFactory CommandDirectoryOptions []command_dir.CommandDirHandlerOption TemplateDirectoryOptions []template_dir.TemplateDirHandlerOption TemplateOptions []template.TemplateHandlerOption // ConfigFileLocation is an optional path to the config file on disk in case it needs to be reloaded ConfigFileLocation string DevMode bool // contains filtered or unexported fields }
ConfigFileHandler contains everything needed to serve a config file
func NewConfigFileHandler ¶
func NewConfigFileHandler( config *config.Config, options ...ConfigFileHandlerOption, ) *ConfigFileHandler
NewConfigFileHandler creates a new config file handler. The actual handlers resulting from the config file are actually created in Serve.
It will use the options passed in using WithAppendCommandDirHandlerOptions and WithAppendTemplateDirHandlerOptions and pass them to the TemplateDir and CommandDir handlers.
TODO(manuel, 2023-06-20) This doesn't allow taking CommandDirOptions and TemplateDirOptions for individual routes.
Also see https://github.com/go-go-golems/parka/issues/51 to allow the individual config file entries to actually provide the options for the handlers.
In a way, the options passed here could be considered "defaults". The order of overrides would be interesting to figure out.
func (*ConfigFileHandler) Serve ¶
func (cfh *ConfigFileHandler) Serve(server_ *server.Server) error
Serve serves the config file by registering all the routers.
To create the handlers, it will walk over each individual route and create the appropriate handler. For example, if the route contains a CommandDirectory, it will create a CommandDirHandler and register it with the server.
NOTE(manuel, 2023-06-20) Creating the handlers late, in the Serve method, is not ideal because it makes it hard for the creating function to override specific handler options if need be (also this could potentially better be handled by setting the right overrides and defaults in the config.Config object upfront).
func (*ConfigFileHandler) Watch ¶
func (cfh *ConfigFileHandler) Watch(ctx context.Context) error
Watch watches the config for changes and updates the server accordingly. Because this will register / unregister routes, this will probably need to be handled at a level where we can restart the gin server altogether.
type ConfigFileHandlerOption ¶
type ConfigFileHandlerOption func(*ConfigFileHandler)
func WithAppendCommandDirHandlerOptions ¶
func WithAppendCommandDirHandlerOptions(options ...command_dir.CommandDirHandlerOption) ConfigFileHandlerOption
func WithAppendTemplateDirHandlerOptions ¶
func WithAppendTemplateDirHandlerOptions(options ...template_dir.TemplateDirHandlerOption) ConfigFileHandlerOption
func WithAppendTemplateHandlerOptions ¶
func WithAppendTemplateHandlerOptions(options ...template.TemplateHandlerOption) ConfigFileHandlerOption
func WithConfigFileLocation ¶
func WithConfigFileLocation(location string) ConfigFileHandlerOption
func WithDevMode ¶
func WithDevMode(devMode bool) ConfigFileHandlerOption
func WithRepositoryFactory ¶
func WithRepositoryFactory(rf RepositoryFactory) ConfigFileHandlerOption
type ErrNoRepositoryFactory ¶
type ErrNoRepositoryFactory struct{}
func (ErrNoRepositoryFactory) Error ¶
func (e ErrNoRepositoryFactory) Error() string
type RepositoryFactory ¶
type RepositoryFactory func(dirs []string) (*repositories.Repository, error)
RepositoryFactory is a function that returns a repository given a list of directories. This is used to provision the CommandDir handlers.