refactor enabled connectors

This commit is contained in:
Bradley Cicenas 2018-01-29 12:47:10 +00:00
parent 01a305d326
commit ac1ce18143
6 changed files with 11 additions and 17 deletions

View File

@ -11,6 +11,8 @@ import (
api "github.com/fsouza/go-dockerclient" api "github.com/fsouza/go-dockerclient"
) )
func init() { enabled["docker"] = NewDocker }
type Docker struct { type Docker struct {
client *api.Client client *api.Client
containers map[string]*container.Container containers map[string]*container.Container

View File

@ -1,7 +0,0 @@
// +build !linux
package connector
var enabled = map[string]func() Connector{
"docker": NewDocker,
}

View File

@ -1,8 +0,0 @@
// +build !darwin
package connector
var enabled = map[string]func() Connector{
"docker": NewDocker,
"runc": NewRunc,
}

View File

@ -7,7 +7,10 @@ import (
"github.com/bcicen/ctop/logging" "github.com/bcicen/ctop/logging"
) )
var log = logging.Init() var (
log = logging.Init()
enabled = make(map[string]func() Connector)
)
func ByName(s string) (Connector, error) { func ByName(s string) (Connector, error) {
if _, ok := enabled[s]; !ok { if _, ok := enabled[s]; !ok {

View File

@ -14,11 +14,13 @@ import (
"github.com/nu7hatch/gouuid" "github.com/nu7hatch/gouuid"
) )
func init() { enabled["mock"] = NewMock }
type Mock struct { type Mock struct {
containers container.Containers containers container.Containers
} }
func NewMock() *Mock { func NewMock() Connector {
cs := &Mock{} cs := &Mock{}
go cs.Init() go cs.Init()
go cs.Loop() go cs.Loop()

View File

@ -17,6 +17,8 @@ import (
"github.com/opencontainers/runc/libcontainer/cgroups/systemd" "github.com/opencontainers/runc/libcontainer/cgroups/systemd"
) )
func init() { enabled["runc"] = NewRunc }
type RuncOpts struct { type RuncOpts struct {
root string // runc root path root string // runc root path
systemdCgroups bool // use systemd cgroups systemdCgroups bool // use systemd cgroups