change: clean code

This commit is contained in:
debugtalk
2022-01-18 20:21:43 +08:00
parent c222b22132
commit b1e405612e
2 changed files with 21 additions and 26 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ func Init(path string) (Plugin, error) {
} }
var plugin Plugin var plugin Plugin
// priority: hashicorp plugin > go plugin > builtin functions // priority: hashicorp plugin > go plugin
// locate hashicorp plugin file // locate hashicorp plugin file
pluginPath, err := locateFile(path, hashicorpGoPluginFile) pluginPath, err := locateFile(path, hashicorpGoPluginFile)
if err == nil { if err == nil {
+20 -25
View File
@@ -193,41 +193,36 @@ func (r *caseRunner) run() error {
} }
func initPlugin(path string) (plugin common.Plugin, err error) { func initPlugin(path string) (plugin common.Plugin, err error) {
defer func() {
if plugin == nil {
return
}
var pluginType string
if _, ok := plugin.(*common.GoPlugin); ok {
pluginType = "go"
} else {
pluginType = "hashicorp"
}
// report event for initializing plugin
event := ga.EventTracking{
Category: "InitPlugin",
Action: fmt.Sprintf("Init %s plugin", pluginType),
}
if err != nil {
event.Value = 1 // failed
}
go ga.SendEvent(event)
}()
plugin, err = common.Init(path) plugin, err = common.Init(path)
if plugin == nil {
return
}
// catch Interrupt and SIGTERM signals to ensure plugin quitted // catch Interrupt and SIGTERM signals to ensure plugin quitted
c := make(chan os.Signal) c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() { go func() {
<-c <-c
if plugin != nil { plugin.Quit()
plugin.Quit()
}
os.Exit(1) os.Exit(1)
}() }()
// report event for initializing plugin
var pluginType string
if _, ok := plugin.(*common.GoPlugin); ok {
pluginType = "go"
} else {
pluginType = "hashicorp"
}
event := ga.EventTracking{
Category: "InitPlugin",
Action: fmt.Sprintf("Init %s plugin", pluginType),
}
if err != nil {
event.Value = 1 // failed
}
go ga.SendEvent(event)
return return
} }