Add dumpers

This commit is contained in:
kolaente 2021-08-18 20:25:59 +02:00
parent d3abd6749f
commit 79f6c5cfad
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 63 additions and 5 deletions

20
dump.go Normal file
View File

@ -0,0 +1,20 @@
package main
import "github.com/docker/docker/api/types"
type Dumper interface {
Dump() error
}
func NewDumperFromContainer(container *types.ContainerJSON) Dumper {
switch container.Config.Image {
case "mysql":
fallthrough
case "mariadb":
return NewMysqlDumper(container)
case "postgres":
return NewPostgresDumper(container)
}
return nil
}

17
dump_mysql.go Normal file
View File

@ -0,0 +1,17 @@
package main
import "github.com/docker/docker/api/types"
type MysqlDumper struct {
Container *types.ContainerJSON
}
func NewMysqlDumper(container *types.ContainerJSON) *MysqlDumper {
return &MysqlDumper{
Container: container,
}
}
func (m *MysqlDumper) Dump() error {
panic("implement me")
}

17
dump_postgres.go Normal file
View File

@ -0,0 +1,17 @@
package main
import "github.com/docker/docker/api/types"
type PostgresDumper struct {
Container *types.ContainerJSON
}
func NewPostgresDumper(container *types.ContainerJSON) *PostgresDumper {
return &PostgresDumper{
Container: container,
}
}
func (p *PostgresDumper) Dump() error {
panic("implement me")
}

View File

@ -2,7 +2,6 @@ package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"log"
@ -10,12 +9,12 @@ import (
)
var (
store map[string]*types.ContainerJSON
store map[string]Dumper
lock sync.Mutex
)
func init() {
store = make(map[string]*types.ContainerJSON)
store = make(map[string]Dumper)
}
func storeContainers(c *client.Client, containers []types.Container) {
@ -32,8 +31,13 @@ func storeContainers(c *client.Client, containers []types.Container) {
log.Fatalf("Could not get Container info: %s", err)
}
store[container.ID] = &info
dumper := NewDumperFromContainer(&info)
if dumper == nil {
continue
}
fmt.Printf("Container: %s, %s image: %s, labels: %v, ip: %v, env: %v\n", info.Name, info.State.Status, info.Image, info.Config.Labels, info.NetworkSettings.Networks, info.Config.Env)
log.Printf("Found container %s\n", container.Names)
store[container.ID] = dumper
}
}