Fix types

This commit is contained in:
Jesse Duffield 2025-11-14 21:08:28 +11:00
parent c7b58683ae
commit 826f0293f1
4 changed files with 22 additions and 27 deletions

View file

@ -1,13 +1,10 @@
linters:
disable:
- structcheck # gives false positives
enable:
- gofumpt
- thelper
- goimports
- tparallel
- wastedassign
- exportloopref
- unparam
- prealloc
- unconvert

View file

@ -7,14 +7,12 @@ import (
"strings"
"github.com/docker/docker/api/types/container"
"github.com/sasha-s/go-deadlock"
dockerTypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazydocker/pkg/i18n"
"github.com/jesseduffield/lazydocker/pkg/utils"
"github.com/sasha-s/go-deadlock"
"github.com/sirupsen/logrus"
"golang.org/x/xerrors"
)
@ -29,12 +27,12 @@ type Container struct {
OneOff bool
ProjectName string
ID string
Container dockerTypes.Container
Container container.Summary
Client *client.Client
OSCommand *OSCommand
Log *logrus.Entry
StatHistory []*RecordedStats
Details dockerTypes.ContainerJSON
Details container.InspectResponse
MonitoringStats bool
DockerCommand LimitedDockerCommand
Tr *i18n.TranslationSet
@ -105,15 +103,15 @@ func (c *Container) Attach() (*exec.Cmd, error) {
}
// Top returns process information
func (c *Container) Top(ctx context.Context) (container.ContainerTopOKBody, error) {
func (c *Container) Top(ctx context.Context) (container.TopResponse, error) {
detail, err := c.Inspect()
if err != nil {
return container.ContainerTopOKBody{}, err
return container.TopResponse{}, err
}
// check container status
if !detail.State.Running {
return container.ContainerTopOKBody{}, errors.New("container is not running")
return container.TopResponse{}, errors.New("container is not running")
}
return c.Client.ContainerTop(ctx, c.ID, []string{})
@ -126,7 +124,7 @@ func (c *DockerCommand) PruneContainers() error {
}
// Inspect returns details about the container
func (c *Container) Inspect() (dockerTypes.ContainerJSON, error) {
func (c *Container) Inspect() (container.InspectResponse, error) {
return c.Client.ContainerInspect(context.Background(), c.ID)
}

View file

@ -6,7 +6,7 @@ import (
"strconv"
"strings"
dockerTypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/fatih/color"
"github.com/jesseduffield/lazydocker/pkg/commands"
"github.com/jesseduffield/lazydocker/pkg/config"
@ -30,7 +30,7 @@ func displayContainerImage(container *commands.Container) string {
}
func displayPorts(c *commands.Container) string {
portStrings := lo.Map(c.Container.Ports, func(port dockerTypes.Port, _ int) string {
portStrings := lo.Map(c.Container.Ports, func(port container.Port, _ int) string {
if port.PublicPort == 0 {
return fmt.Sprintf("%d/%s", port.PrivatePort, port.Type)
}

View file

@ -4,7 +4,7 @@ import (
"sort"
"testing"
dockerTypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/jesseduffield/lazydocker/pkg/commands"
"github.com/stretchr/testify/assert"
)
@ -14,28 +14,28 @@ func sampleContainers() []*commands.Container {
{
ID: "1",
Name: "1",
Container: dockerTypes.Container{
Container: container.Summary{
State: "exited",
},
},
{
ID: "2",
Name: "2",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "3",
Name: "3",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "4",
Name: "4",
Container: dockerTypes.Container{
Container: container.Summary{
State: "created",
},
},
@ -47,28 +47,28 @@ func expectedPerStatusContainers() []*commands.Container {
{
ID: "2",
Name: "2",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "3",
Name: "3",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "1",
Name: "1",
Container: dockerTypes.Container{
Container: container.Summary{
State: "exited",
},
},
{
ID: "4",
Name: "4",
Container: dockerTypes.Container{
Container: container.Summary{
State: "created",
},
},
@ -80,28 +80,28 @@ func expectedLegacySortedContainers() []*commands.Container {
{
ID: "1",
Name: "1",
Container: dockerTypes.Container{
Container: container.Summary{
State: "exited",
},
},
{
ID: "2",
Name: "2",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "3",
Name: "3",
Container: dockerTypes.Container{
Container: container.Summary{
State: "running",
},
},
{
ID: "4",
Name: "4",
Container: dockerTypes.Container{
Container: container.Summary{
State: "created",
},
},