...the good news is, it's easy!
- Create a directory named
yourplugin
under directoryplugins
- Under
yourplugin
, you need three more packages:api
,models
andtasks
api
interacts withconfig-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 alldata entities
anddata migration scripts
. Please check How to create models and data migrations for detail.tasks
contains all of oursub tasks
for a plugin
- Create a yourplugin.go in
yourplugin
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.
- Create collector will collect data from remote api server and save into raw layer
- Create extractor will extract data from raw layer and save into tool layer
- Create convertor will convert data from tool layer and save into domain layer
Congratulations! You have created your first plugin! 🎖