Replaced calls to WriteRune with WriteByte and reformatted imports

Signed-off-by: Benjamín Guzmán <bg@benjaminguzman.dev>
This commit is contained in:
Benjamín Guzmán 2023-03-28 14:05:06 -06:00 committed by Nicolas De loof
parent 2268d1e573
commit 2bc6a45c0b

View File

@ -19,11 +19,12 @@ package compose
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra"
) )
type vizOptions struct { type vizOptions struct {
@ -65,7 +66,7 @@ func vizCommand(p *ProjectOptions) *cobra.Command {
return cmd return cmd
} }
func runViz(ctx context.Context, opts *vizOptions) error { func runViz(_ context.Context, opts *vizOptions) error {
_, _ = fmt.Fprintln(os.Stderr, "viz command is EXPERIMENTAL") _, _ = fmt.Fprintln(os.Stderr, "viz command is EXPERIMENTAL")
project, err := opts.ToProject(nil) project, err := opts.ToProject(nil)
if err != nil { if err != nil {
@ -89,7 +90,7 @@ func runViz(ctx context.Context, opts *vizOptions) error {
graphBuilder.WriteString("digraph " + project.Name + " {\n") graphBuilder.WriteString("digraph " + project.Name + " {\n")
graphBuilder.WriteString(opts.indentationStr + "layout=dot;\n") graphBuilder.WriteString(opts.indentationStr + "layout=dot;\n")
addNodes(&graphBuilder, graph, opts) addNodes(&graphBuilder, graph, opts)
graphBuilder.WriteRune('\n') graphBuilder.WriteByte('\n')
addEdges(&graphBuilder, graph, opts) addEdges(&graphBuilder, graph, opts)
graphBuilder.WriteString("}\n") graphBuilder.WriteString("}\n")
@ -127,10 +128,10 @@ func addNodes(graphBuilder *strings.Builder, graph vizGraph, opts *vizOptions) *
graphBuilder.WriteString("<br/>") graphBuilder.WriteString("<br/>")
if len(portConfig.HostIP) > 0 { if len(portConfig.HostIP) > 0 {
graphBuilder.WriteString(portConfig.HostIP) graphBuilder.WriteString(portConfig.HostIP)
graphBuilder.WriteRune(':') graphBuilder.WriteByte(':')
} }
graphBuilder.WriteString(portConfig.Published) graphBuilder.WriteString(portConfig.Published)
graphBuilder.WriteRune(':') graphBuilder.WriteByte(':')
graphBuilder.WriteString(strconv.Itoa(int(portConfig.Target))) graphBuilder.WriteString(strconv.Itoa(int(portConfig.Target)))
graphBuilder.WriteString(" (") graphBuilder.WriteString(" (")
graphBuilder.WriteString(portConfig.Protocol) graphBuilder.WriteString(portConfig.Protocol)
@ -172,9 +173,9 @@ func addEdges(graphBuilder *strings.Builder, graph vizGraph, opts *vizOptions) *
// writeQuoted writes "str" to builder // writeQuoted writes "str" to builder
func writeQuoted(builder *strings.Builder, str string) { func writeQuoted(builder *strings.Builder, str string) {
builder.WriteRune('"') builder.WriteByte('"')
builder.WriteString(str) builder.WriteString(str)
builder.WriteRune('"') builder.WriteByte('"')
} }
// preferredIndentationStr returns a single string given the indentation preference // preferredIndentationStr returns a single string given the indentation preference