{"modulePath":"github.com/hellofresh/janus","version":"v0.0.0-20230925145208-ce8de8183c67","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Constants\n\n```go\nconst (\n\tStartupEvent         = \"startup\"\n\tAdminAPIStartupEvent = \"admin_startup\"\n\n\tReloadEvent   = \"reload\"\n\tShutdownEvent = \"shutdown\"\n\tSetupEvent    = \"setup\"\n)\n```\nDefine the event names for the startup and shutdown events\n\n## Functions\n\n```go\nfunc Decode(rawConfig map[string]interface{}, obj interface{}) error\n```\nDecode decodes a map string interface into a struct for some reasons mapstructure.Decode() gives empty arrays for all resulting config fields this is quick workaround hack t make it work FIXME: investigate and fix mapstructure.Decode() behaviour and remove this dirty hack\n\n```go\nfunc EmitEvent(name string, event interface{}) error\n```\nEmitEvent executes the different hooks passing the EventType as an argument. This is a blocking function. Hook developers should use 'go' keyword if they don't want to block Janus.\n\n```go\nfunc RegisterEventHook(name string, hook EventHook) error\n```\nRegisterEventHook plugs in hook. All the hooks should register themselves and they must have a name.\n\n```go\nfunc RegisterPlugin(name string, plugin Plugin) error\n```\nRegisterPlugin plugs in plugin. All plugins should register themselves, even if they do not perform an action associated with a directive. It is important for the process to know which plugins are available.\n\nThe plugin MUST have a name: lower case and one word. If this plugin has an action, it must be the name of the directive that invokes it. A name is always required and must be unique for the server type.\n\n```go\nfunc ValidateConfig(name string, rawConfig Config) (bool, error)\n```\nValidateConfig validates the plugin configuration data\n\n## Types\n\n```go\ntype Config map[string]interface{}\n```\nConfig initialization options.\n\n```go\ntype EventHook func(event interface{}) error\n```\nEventHook is a type which holds information about a startup hook plugin.\n\n```go\ntype OnAdminAPIStartup struct {\n\tRouter router.Router\n}\n```\nOnAdminAPIStartup represents a event that happens when Janus starts up the admin API\n\n```go\ntype OnReload struct {\n\tConfigurations []*api.Definition\n}\n```\nOnReload represents a event that happens when Janus hot reloads it's configurations\n\n```go\ntype OnStartup struct {\n\tStatsClient   client.Client\n\tMongoDB       *mongo.Database\n\tCassandra     wrapper.Holder\n\tRegister      *proxy.Register\n\tConfig        *config.Specification\n\tConfiguration []*api.Definition\n}\n```\nOnStartup represents a event that happens when Janus starts up on the main process\n\n```go\ntype Plugin struct {\n\tAction   SetupFunc\n\tValidate ValidateFunc\n}\n```\nPlugin defines basic methods for plugins\n\n```go\ntype SetupFunc func(def *proxy.RouterDefinition, rawConfig Config) error\n```\nSetupFunc is used to set up a plugin, or in other words, execute a directive. It will be called once per key for each server block it appears in.\n\n```go\nfunc DirectiveAction(name string) (SetupFunc, error)\n```\nDirectiveAction gets the action for a plugin\n\n```go\ntype ValidateFunc func(rawConfig Config) (bool, error)\n```\nValidateFunc validates configuration data against the plugin struct\n\n","path":"github.com/hellofresh/janus/pkg/plugin","name":"plugin","synopsis":"","isRedistributable":true}
