Skip to content

Commit

Permalink
chore: upgrade go version, cleanup code, update dependencies (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho authored Feb 27, 2024
1 parent 7dfaeeb commit ff9ecf6
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 1,381 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VE
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"
GOOSES = darwin freebsd linux windows
GOARCHS = amd64 386 arm arm64
GOARCHS = amd64 386 arm arm64
UNSUPPORTED = darwin_arm darwin_386 windows_arm windows_arm64 windows_386 freebsd_arm64
print-%: ; @echo $*=$($*)

run: ## Runs dry
GO111MODULE=on go run ./main.go
go run ./main.go

build: ## Builds dry
GO111MODULE=on go build .
go build .

install: ## Installs dry
GO111MODULE=on go install $(PKG)
go install $(PKG)

lint: ## Runs linters
@echo ">> CODE QUALITY"
Expand Down Expand Up @@ -56,15 +56,15 @@ fmt: ## Runs fmt
@gofmt -s -l -w $(GOFILES_NOVENDOR)

test: ## Run tests
GO111MODULE=on go test -v -cover $(shell go list ./... | grep -v /vendor/ | grep -v mock)
go test -v -cover $(shell go list ./... | grep -v /vendor/ | grep -v mock)

benchmark: ## Run benchmarks
GO111MODULE=on go test -bench $(shell go list ./... | grep -v /vendor/ | grep -v mock)
go test -bench $(shell go list ./... | grep -v /vendor/ | grep -v mock)

define buildpretty
$(if $(and $(filter-out $(UNSUPPORTED),$(1)_$(2))), \
mkdir -p ${PREFIX}/cross/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 GO111MODULE=on go build -o ${PREFIX}/cross/$(1)/$(2)/dry -a ${GO_LDFLAGS} .;
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o ${PREFIX}/cross/$(1)/$(2)/dry -a ${GO_LDFLAGS} .;
)
endef

Expand All @@ -74,7 +74,7 @@ cross: *.go VERSION ## Cross compiles dry
define buildrelease
$(if $(and $(filter-out $(UNSUPPORTED),$(1)_$(2))), \
mkdir -p ${PREFIX}/cross/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 GO111MODULE=on go build -o ${PREFIX}/cross/dry-$(1)-$(2) -a ${GO_LDFLAGS} .;
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o ${PREFIX}/cross/dry-$(1)-$(2) -a ${GO_LDFLAGS} .;
)
endef

Expand Down
20 changes: 10 additions & 10 deletions app/dry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/moncho/dry/ui/termui"
)

//Dry resources and state
// Dry resources and state
type Dry struct {
dockerDaemon docker.ContainerDaemon
dockerEvents <-chan events.Message
Expand All @@ -37,23 +37,23 @@ func (d *Dry) toggleShowHeader() {
d.showHeader = !d.showHeader
}

//Close closes dry, releasing any resources held by it
// Close closes dry, releasing any resources held by it
func (d *Dry) Close() {
close(d.dockerEventsDone)
close(d.output)
}

//OuputChannel returns the channel where dry messages are written
// OuputChannel returns the channel where dry messages are written
func (d *Dry) OuputChannel() <-chan string {
return d.output
}

//Ok returns the state of dry
// Ok returns the state of dry
func (d *Dry) Ok() (bool, error) {
return d.dockerDaemon.Ok()
}

//changeView changes the active view mode
// changeView changes the active view mode
func (d *Dry) changeView(v viewMode) {
d.Lock()
defer d.Unlock()
Expand All @@ -66,19 +66,19 @@ func (d *Dry) showDockerEvents() {
for event := range d.dockerEvents {
//exec_ messages are sent continuously if docker is checking
//a container's health, so they are ignored
if strings.Contains(event.Action, "exec_") {
if strings.Contains(string(event.Action), "exec_") {
continue
}
//top messages are sent continuously on monitor mode, ignored
if strings.Contains(event.Action, "top") {
if strings.Contains(string(event.Action), "top") {
continue
}
d.message(fmt.Sprintf("Docker: %s %s", event.Action, event.ID))
}
}()
}

//message publishes the given message
// message publishes the given message
func (d *Dry) message(message string) {
select {
case d.output <- message:
Expand All @@ -101,7 +101,7 @@ func (d *Dry) viewMode() viewMode {
return d.view
}

//initRegistry creates a widget registry with its widget ready to be used
// initRegistry creates a widget registry with its widget ready to be used
func initRegistry(dry *Dry) *widgetRegistry {
daemon := dry.dockerDaemon
mainScreen := dry.screen
Expand Down Expand Up @@ -164,7 +164,7 @@ func newDry(screen *ui.Screen, d *docker.DockerDaemon) (*Dry, error) {

}

//NewDry creates a new dry application
// NewDry creates a new dry application
func NewDry(screen *ui.Screen, cfg Config) (*Dry, error) {

d, err := docker.ConnectToDaemon(cfg.dockerEnv())
Expand Down
11 changes: 6 additions & 5 deletions appui/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
units "github.com/docker/go-units"
"github.com/moncho/dry/docker"
)
Expand All @@ -19,7 +20,7 @@ const (
defaultDiskUsageTableFormat = "{{.Type}}\t{{.TotalCount}}\t{{.Active}}\t{{.Size}}\t{{.Reclaimable}}"
)

//DockerDiskUsageRenderer renderer for Docker disk usage
// DockerDiskUsageRenderer renderer for Docker disk usage
type DockerDiskUsageRenderer struct {
columns []string
diskUsageTableTemplate *template.Template
Expand All @@ -30,7 +31,7 @@ type DockerDiskUsageRenderer struct {
sync.RWMutex
}

//NewDockerDiskUsageRenderer creates a DockerDiskUsageRenderer
// NewDockerDiskUsageRenderer creates a DockerDiskUsageRenderer
func NewDockerDiskUsageRenderer(screenHeight int) *DockerDiskUsageRenderer {
r := &DockerDiskUsageRenderer{}

Expand All @@ -47,7 +48,7 @@ func NewDockerDiskUsageRenderer(screenHeight int) *DockerDiskUsageRenderer {
return r
}

//PrepareToRender passes the data to be rendered
// PrepareToRender passes the data to be rendered
func (r *DockerDiskUsageRenderer) PrepareToRender(diskUsage *types.DiskUsage, report *docker.PruneReport) {
r.Lock()
r.diskUsage = diskUsage
Expand All @@ -58,7 +59,7 @@ func (r *DockerDiskUsageRenderer) PrepareToRender(diskUsage *types.DiskUsage, re
r.Unlock()
}

//Render returns the result of docker system df
// Render returns the result of docker system df
func (r *DockerDiskUsageRenderer) String() string {
r.RLock()
defer r.RUnlock()
Expand Down Expand Up @@ -285,7 +286,7 @@ func (c *diskUsageContainersContext) Reclaimable() string {
}

type diskUsageVolumesContext struct {
volumes []*types.Volume
volumes []*volume.Volume
}

func (c *diskUsageVolumesContext) Type() string {
Expand Down
24 changes: 8 additions & 16 deletions appui/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import (
"sort"
"strings"

dockerTypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/go-units"
)

type infoRenderer struct {
env dockerTypes.Info
env system.Info
}

//NewDockerInfoRenderer creates renderer for for docker info
func NewDockerInfoRenderer(env dockerTypes.Info) fmt.Stringer {
// NewDockerInfoRenderer creates renderer for for docker info
func NewDockerInfoRenderer(env system.Info) fmt.Stringer {
return &infoRenderer{
env: env,
}
}

//Render system-wide information
// Render system-wide information
func (r *infoRenderer) String() string {

buffer := new(bytes.Buffer)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (r *infoRenderer) String() string {

for _, ci := range []struct {
name string
commit dockerTypes.Commit
commit system.Commit
}{
{"containerd", info.ContainerdCommit},
{"runc", info.RuncCommit},
Expand All @@ -142,7 +142,7 @@ func (r *infoRenderer) String() string {
buffer.WriteString("")
}
if len(info.SecurityOptions) != 0 {
kvs, err := dockerTypes.DecodeSecurityOptions(info.SecurityOptions)
kvs, err := system.DecodeSecurityOptions(info.SecurityOptions)
if err == nil {
buffer.WriteString("<white> Security Options:</>\n")
for _, so := range kvs {
Expand Down Expand Up @@ -257,14 +257,6 @@ func (r *infoRenderer) String() string {
}

writeKV(buffer, "Experimental", info.ExperimentalBuild)
if info.ClusterStore != "" {
writeKV(buffer, "Cluster Store", info.ClusterStore)
}

if info.ClusterAdvertise != "" {
writeKV(buffer, "Cluster Advertise", info.ClusterAdvertise)
}

if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) {
buffer.WriteString("<white> Insecure Registries:</>\n")
for _, registry := range info.RegistryConfig.IndexConfigs {
Expand Down Expand Up @@ -293,7 +285,7 @@ func writeKVIfNotEmpty(buffer *bytes.Buffer, key string, value interface{}) {
}
}

//writeKV write into the given buffer "key: value"
// writeKV write into the given buffer "key: value"
func writeKV(buffer *bytes.Buffer, key string, value interface{}) {
buffer.WriteString(fmt.Sprintf("<white> %s </>: %v\n", key, value))
}
10 changes: 5 additions & 5 deletions appui/volume_row.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package appui

import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/volume"
termui "github.com/gizak/termui"
drytermui "github.com/moncho/dry/ui/termui"
)

// VolumeRow is a Grid row showing information about a Docker volume.
type VolumeRow struct {
volume *types.Volume
volume *volume.Volume
Driver *drytermui.ParColumn
Name *drytermui.ParColumn
Row
}

//NewVolumeRow creates VolumeRow widgets.
func NewVolumeRow(volume *types.Volume, table drytermui.Table) *VolumeRow {
// NewVolumeRow creates VolumeRow widgets.
func NewVolumeRow(volume *volume.Volume, table drytermui.Table) *VolumeRow {

row := &VolumeRow{
volume: volume,
Expand All @@ -38,7 +38,7 @@ func NewVolumeRow(volume *types.Volume, table drytermui.Table) *VolumeRow {

}

//ColumnsForFilter returns the columns that are used to filter
// ColumnsForFilter returns the columns that are used to filter
func (row *VolumeRow) ColumnsForFilter() []*drytermui.ParColumn {
return []*drytermui.ParColumn{row.Name, row.Driver}
}
27 changes: 13 additions & 14 deletions appui/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (
"strings"
"sync"

"github.com/docker/docker/api/types"
"github.com/moncho/dry/ui/termui"

"github.com/docker/docker/api/types/volume"
gizaktermui "github.com/gizak/termui"
"github.com/moncho/dry/ui/termui"
)

type volumesService interface {
VolumeList(ctx context.Context) ([]*types.Volume, error)
VolumeList(ctx context.Context) ([]*volume.Volume, error)
}

const (
Expand All @@ -30,7 +29,7 @@ var volumesTableHeaders = []SortableColumnHeader{
{`VOLUME NAME`, byName},
}

//VolumesWidget shows information containers
// VolumesWidget shows information containers
type VolumesWidget struct {
service volumesService
totalRows []*VolumeRow
Expand All @@ -46,7 +45,7 @@ type VolumesWidget struct {
mounted bool
}

//NewVolumesWidget creates a VolumesWidget
// NewVolumesWidget creates a VolumesWidget
func NewVolumesWidget(service volumesService, s Screen) *VolumesWidget {
return &VolumesWidget{
header: volumesTableHeader(),
Expand All @@ -55,7 +54,7 @@ func NewVolumesWidget(service volumesService, s Screen) *VolumesWidget {
sortBy: byDriver}
}

//Buffer returns the content of this widget as a termui.Buffer
// Buffer returns the content of this widget as a termui.Buffer
func (s *VolumesWidget) Buffer() gizaktermui.Buffer {
s.Lock()
defer s.Unlock()
Expand Down Expand Up @@ -99,15 +98,15 @@ func (s *VolumesWidget) Buffer() gizaktermui.Buffer {
return buf
}

//Filter applies the given filter to the container list
// Filter applies the given filter to the container list
func (s *VolumesWidget) Filter(filter string) {
s.Lock()
defer s.Unlock()
s.filterPattern = filter

}

//Mount tells this widget to be ready for rendering
// Mount tells this widget to be ready for rendering
func (s *VolumesWidget) Mount() error {
s.Lock()
defer s.Unlock()
Expand All @@ -130,12 +129,12 @@ func (s *VolumesWidget) Mount() error {
return nil
}

//Name returns this widget name
// Name returns this widget name
func (s *VolumesWidget) Name() string {
return "VolumesWidget"
}

//OnEvent runs the given command
// OnEvent runs the given command
func (s *VolumesWidget) OnEvent(event EventCommand) error {
if s.RowCount() <= 0 {
return errors.New("The volume list is empty")
Expand All @@ -145,12 +144,12 @@ func (s *VolumesWidget) OnEvent(event EventCommand) error {
return event(s.filteredRows[s.selectedIndex].Name.Text)
}

//RowCount returns the number of rows of this widget.
// RowCount returns the number of rows of this widget.
func (s *VolumesWidget) RowCount() int {
return len(s.filteredRows)
}

//Sort rotates to the next sort mode.
// Sort rotates to the next sort mode.
func (s *VolumesWidget) Sort() {
s.Lock()
defer s.Unlock()
Expand All @@ -169,7 +168,7 @@ func (s *VolumesWidget) Unmount() error {
return nil
}

//Align aligns rows
// Align aligns rows
func (s *VolumesWidget) align() {
x := s.screen.Bounds().Min.X
width := s.screen.Bounds().Dx()
Expand Down
Loading

0 comments on commit ff9ecf6

Please sign in to comment.