Unverified 提交 3453f0eb 作者: Steven Allen 提交者: GitHub

Merge pull request #6672 from MichaelMure/plugin-tracer-close

plugins: support Close() for Tracer plugins as well
...@@ -10,5 +10,4 @@ type PluginDaemon interface { ...@@ -10,5 +10,4 @@ type PluginDaemon interface {
Plugin Plugin
Start(coreiface.CoreAPI) error Start(coreiface.CoreAPI) error
Close() error
} }
...@@ -2,6 +2,7 @@ package loader ...@@ -2,6 +2,7 @@ package loader
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -266,8 +267,8 @@ func (loader *PluginLoader) Close() error { ...@@ -266,8 +267,8 @@ func (loader *PluginLoader) Close() error {
started := loader.started started := loader.started
loader.started = nil loader.started = nil
for _, pl := range started { for _, pl := range started {
if pl, ok := pl.(plugin.PluginDaemon); ok { if closer, ok := pl.(io.Closer); ok {
err := pl.Close() err := closer.Close()
if err != nil { if err != nil {
errs = append(errs, fmt.Sprintf( errs = append(errs, fmt.Sprintf(
"error closing plugin %s: %s", "error closing plugin %s: %s",
......
...@@ -9,8 +9,11 @@ type Environment struct { ...@@ -9,8 +9,11 @@ type Environment struct {
Config interface{} Config interface{}
} }
// Plugin is base interface for all kinds of go-ipfs plugins // Plugin is the base interface for all kinds of go-ipfs plugins
// It will be included in interfaces of different Plugins // It will be included in interfaces of different Plugins
//
// Optionally, Plugins can implement io.Closer if they want to
// have a termination step when unloading.
type Plugin interface { type Plugin interface {
// Name should return unique name of the plugin // Name should return unique name of the plugin
Name() string Name() string
......
...@@ -7,5 +7,6 @@ import ( ...@@ -7,5 +7,6 @@ import (
// PluginTracer is an interface that can be implemented to add a tracer // PluginTracer is an interface that can be implemented to add a tracer
type PluginTracer interface { type PluginTracer interface {
Plugin Plugin
InitTracer() (opentracing.Tracer, error) InitTracer() (opentracing.Tracer, error)
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论