ctop/connector/main.go

36 lines
635 B
Go
Raw Normal View History

2017-06-08 15:01:08 +00:00
package connector
import (
2017-06-14 13:11:40 +00:00
"fmt"
"sort"
2017-06-14 13:11:40 +00:00
2017-06-08 15:01:08 +00:00
"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/logging"
)
2018-01-29 12:47:10 +00:00
var (
log = logging.Init()
enabled = make(map[string]func() Connector)
)
2017-06-08 15:01:08 +00:00
// return names for all enabled connectors on the current platform
func Enabled() (a []string) {
for k, _ := range enabled {
a = append(a, k)
}
sort.Strings(a)
return a
}
2017-06-14 13:11:40 +00:00
func ByName(s string) (Connector, error) {
if cfn, ok := enabled[s]; ok {
return cfn(), nil
2017-06-14 13:11:40 +00:00
}
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
2017-06-14 13:11:40 +00:00
}
2017-06-09 17:35:29 +00:00
type Connector interface {
2017-06-08 15:01:08 +00:00
All() container.Containers
Get(string) (*container.Container, bool)
}