...the good news is, it's easy!
yourplugin
under directory plugins
yourplugin
, you need three more packages: api
, models
and tasks
api
interacts with config-ui
for test/get/save connection of data source. Please check How to create connection to be used by config-ui for a data source for detail.models
stores all data entities
and data migration scripts
. Please check How to create models and data migrations for detail.tasks
contains all of our sub tasks
for a pluginyourplugin
type YourPlugin struct{} var _ core.PluginMeta = (*YourPlugin)(nil) var _ core.PluginInit = (*YourPlugin)(nil) var _ core.PluginTask = (*YourPlugin)(nil) var _ core.PluginApi = (*YourPlugin)(nil) var _ core.Migratable = (*YourPlugin)(nil) func (plugin YourPlugin) Init(config *viper.Viper, logger core.Logger, db *gorm.DB) error { return nil } func (plugin YourPlugin) Description() string { return "To collect and enrich data from YourPlugin" } // Register all subtasks func (plugin YourPlugin) SubTaskMetas() []core.SubTaskMeta { return []core.SubTaskMeta{ tasks.CollectXXXX, tasks.ExtractXXXX, tasks.ConvertXXXX, } } // Prepare your apiClient which will be used to request remote api, // `apiClient` is defined in `client.go` under `tasks` // `YourPluginTaskData` is defined in `task_data.go` under `tasks` func (plugin YourPlugin) PrepareTaskData(taskCtx core.TaskContext, options map[string]interface{}) (interface{}, error) { var op tasks.YourPluginOptions err := mapstructure.Decode(options, &op) if err != nil { return nil, err } // Handle error. if err != nil { logger.Error(err) } // Export a variable named PluginEntry for Framework to search and load var PluginEntry YourPlugin //nolint }
To build a new plugin you will need a few things. You should choose an API that you'd like to see data from. Think about the metrics you would like to see first, and then look for data that can support those metrics.
Congratulations! You have created your first plugin! 🎖