Skip to content

Commit 3e62a6a

Browse files
authored
👻 Go 1.20. (#55)
upgrade Go 1.20. Replaces gofmt with goimports. Documentation claims it performs the same formatting plus manages/orders imports. Added missing packages in Makefile. Updated the go.mod and ran go mod tidy. Updated cmd/main.go to include sub-packages so they're compiled. closes: #44 NOT FOR 0.3. --------- Signed-off-by: Jeff Ortel <jortel@redhat.com>
1 parent ae17832 commit 3e62a6a

File tree

9 files changed

+40
-51
lines changed

9 files changed

+40
-51
lines changed

Makefile

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
GOBIN ?= ${GOPATH}/bin
1+
GOPATH ?= $(HOME)/go
2+
GOBIN ?= $(GOPATH)/bin
3+
GOIMPORTS = $(GOBIN)/goimports
4+
5+
PKG = ./cmd/... \
6+
./command/... \
7+
./repository/... \
8+
./ssh/...
9+
10+
PKGDIR = $(subst /...,,$(PKG))
211

312
all: cmd
413

5-
fmt:
6-
go fmt ./...
14+
fmt: $(GOIMPORTS)
15+
$(GOIMPORTS) -w $(PKGDIR)
716

817
vet:
9-
go vet ./...
18+
go vet $(PKG)
1019

1120
cmd: fmt vet
1221
go build -ldflags="-w -s" -o bin/addon github.com/konveyor/tackle2-addon/cmd
22+
23+
# Ensure goimports installed.
24+
$(GOIMPORTS):
25+
go install golang.org/x/tools/cmd/goimports@latest

cmd/main.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package main
22

33
import (
4-
hub "github.com/konveyor/tackle2-hub/addon"
5-
)
6-
7-
var (
8-
addon = hub.Addon
4+
"github.com/konveyor/tackle2-addon/command"
5+
"github.com/konveyor/tackle2-addon/repository"
6+
"github.com/konveyor/tackle2-addon/ssh"
97
)
108

119
func main() {
12-
addon.Run(func() (err error) {
13-
return
14-
})
10+
_ = command.New("")
11+
_ = ssh.Agent{}
12+
_, _ = repository.New("", nil, nil)
1513
}

command/cmd.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ import (
99
"fmt"
1010
"os/exec"
1111

12-
hub "github.com/konveyor/tackle2-hub/addon"
1312
"path"
13+
14+
hub "github.com/konveyor/tackle2-hub/addon"
1415
)
1516

1617
var (
1718
addon = hub.Addon
1819
)
1920

20-
//
2121
// New returns a command.
2222
func New(path string) (cmd *Command) {
2323
cmd = &Command{Path: path}
2424
return
2525
}
2626

27-
//
2827
// Command execution.
2928
type Command struct {
3029
Options Options
@@ -34,7 +33,6 @@ type Command struct {
3433
Writer Writer
3534
}
3635

37-
//
3836
// Run executes the command.
3937
// The command and output are both reported in
4038
// task Report.Activity.
@@ -43,7 +41,6 @@ func (r *Command) Run() (err error) {
4341
return
4442
}
4543

46-
//
4744
// RunWith executes the command with context.
4845
// The command and output are both reported in
4946
// task Report.Activity.
@@ -76,7 +73,6 @@ func (r *Command) RunWith(ctx context.Context) (err error) {
7673
return
7774
}
7875

79-
//
8076
// RunSilent executes the command.
8177
// On error: The command (without arguments) and output are
8278
// reported in task Report.Activity
@@ -86,24 +82,20 @@ func (r *Command) RunSilent() (err error) {
8682
return
8783
}
8884

89-
//
9085
// Output returns the command output.
9186
func (r *Command) Output() (b []byte) {
9287
return r.Writer.buffer
9388
}
9489

95-
//
9690
// Options are CLI options.
9791
type Options []string
9892

99-
//
10093
// Add option.
10194
func (a *Options) Add(option string, s ...string) {
10295
*a = append(*a, option)
10396
*a = append(*a, s...)
10497
}
10598

106-
//
10799
// Addf option.
108100
func (a *Options) Addf(option string, x ...interface{}) {
109101
*a = append(*a, fmt.Sprintf(option, x...))

command/reporter.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package command
22

33
import (
44
"strings"
5+
56
"github.com/konveyor/tackle2-hub/api"
67
)
78

8-
//
99
// Verbosity.
1010
const (
1111
// Disabled reports: NOTHING.
@@ -18,15 +18,13 @@ const (
1818
LiveOutput = 1
1919
)
2020

21-
//
2221
// Reporter activity reporter.
2322
type Reporter struct {
2423
Verbosity int
2524
file *api.File
2625
index int
2726
}
2827

29-
//
3028
// Run reports command started in task Report.Activity.
3129
func (r *Reporter) Run(path string, options Options) {
3230
switch r.Verbosity {
@@ -41,7 +39,6 @@ func (r *Reporter) Run(path string, options Options) {
4139
}
4240
}
4341

44-
//
4542
// Succeeded reports command succeeded in task Report.Activity.
4643
func (r *Reporter) Succeeded(path string, output []byte) {
4744
switch r.Verbosity {
@@ -59,7 +56,6 @@ func (r *Reporter) Succeeded(path string, output []byte) {
5956
}
6057
}
6158

62-
//
6359
// Error reports command failed in task Report.Activity.
6460
func (r *Reporter) Error(path string, err error, output []byte) {
6561
if len(output) == 0 {
@@ -82,7 +78,6 @@ func (r *Reporter) Error(path string, err error, output []byte) {
8278
}
8379
}
8480

85-
//
8681
// Output reports command output.
8782
func (r *Reporter) Output(buffer []byte) (reported int) {
8883
switch r.Verbosity {
@@ -103,7 +98,6 @@ func (r *Reporter) Output(buffer []byte) (reported int) {
10398
return
10499
}
105100

106-
//
107101
// append output.
108102
func (r *Reporter) append(batch []byte) {
109103
if r.file == nil {

command/writer.go

-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const (
1313
MinBackoff = Backoff
1414
)
1515

16-
//
1716
// Writer records command output.
1817
type Writer struct {
1918
reporter *Reporter
@@ -23,7 +22,6 @@ type Writer struct {
2322
ended chan any
2423
}
2524

26-
//
2725
// Write command output.
2826
func (w *Writer) Write(p []byte) (n int, err error) {
2927
n = len(p)
@@ -39,7 +37,6 @@ func (w *Writer) Write(p []byte) (n int, err error) {
3937
return
4038
}
4139

42-
//
4340
// End of writing.
4441
func (w *Writer) End() {
4542
if w.end == nil {
@@ -51,7 +48,6 @@ func (w *Writer) End() {
5148
w.end = nil
5249
}
5350

54-
//
5551
// report in task Report.Activity.
5652
// Rate limited.
5753
func (w *Writer) report() {
@@ -72,7 +68,6 @@ func (w *Writer) report() {
7268
w.ended <- true
7369
}
7470

75-
//
7671
// adjustBackoff adjust the backoff as needed.
7772
// incremented when output reported.
7873
// decremented when no outstanding output reported.

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/konveyor/tackle2-addon
22

3-
go 1.18
3+
go 1.20
44

55
require (
66
github.com/clbanning/mxj v1.8.4
77
github.com/jortel/go-utils v0.1.2
8-
github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6
8+
github.com/konveyor/tackle2-hub v0.3.0-rc.4.0.20240123170057-e18a6547d4af
99
)
1010

1111
require (

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
121121
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
122122
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
123123
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
124-
github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6 h1:xPLwmNqA3QxVaqqnhF6v/T2ZMTCom2GcROD2BEJIHnQ=
125-
github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6/go.mod h1:ZR4A0+Wp0H3QZkMohPnvZjxcolVORP3jdHV9Uwb/PoE=
124+
github.com/konveyor/tackle2-hub v0.3.0-rc.4.0.20240123170057-e18a6547d4af h1:Msqxh91TToZFmtbySbLShaUyVfqeq5SNWPQywOPOLHk=
125+
github.com/konveyor/tackle2-hub v0.3.0-rc.4.0.20240123170057-e18a6547d4af/go.mod h1:97Z3kWWmPERNl58XkpQkV/F+jnqNNDAVpL9m9XTZmdo=
126126
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
127127
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
128128
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

repository/git.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package repository
33
import (
44
"errors"
55
"fmt"
6+
urllib "net/url"
7+
"os"
8+
pathlib "path"
9+
"strings"
10+
611
liberr "github.com/jortel/go-utils/error"
712
"github.com/konveyor/tackle2-addon/command"
813
"github.com/konveyor/tackle2-addon/ssh"
914
"github.com/konveyor/tackle2-hub/api"
1015
"github.com/konveyor/tackle2-hub/nas"
11-
urllib "net/url"
12-
"os"
13-
pathlib "path"
14-
"strings"
1516
)
1617

1718
// Git repository.

ssh/ssh.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package ssh
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
pathlib "path"
8+
"strings"
9+
"time"
10+
611
liberr "github.com/jortel/go-utils/error"
712
"github.com/konveyor/tackle2-addon/command"
813
hub "github.com/konveyor/tackle2-hub/addon"
914
"github.com/konveyor/tackle2-hub/api"
1015
"github.com/konveyor/tackle2-hub/nas"
11-
"os"
12-
pathlib "path"
13-
"strings"
14-
"time"
1516
)
1617

1718
var (
@@ -28,12 +29,10 @@ func init() {
2829

2930
}
3031

31-
//
3232
// Agent agent.
3333
type Agent struct {
3434
}
3535

36-
//
3736
// Start the ssh-agent.
3837
func (r *Agent) Start() (err error) {
3938
pid := os.Getpid()
@@ -55,7 +54,6 @@ func (r *Agent) Start() (err error) {
5554
return
5655
}
5756

58-
//
5957
// Add ssh key.
6058
func (r *Agent) Add(id *api.Identity, host string) (err error) {
6159
if id.Key == "" {
@@ -132,7 +130,6 @@ func (r *Agent) Add(id *api.Identity, host string) (err error) {
132130
return
133131
}
134132

135-
//
136133
// Ensure key formatting.
137134
func (r *Agent) format(in string) (out string) {
138135
if in != "" {
@@ -141,7 +138,6 @@ func (r *Agent) format(in string) (out string) {
141138
return
142139
}
143140

144-
//
145141
// writeAsk writes script that returns the key password.
146142
func (r *Agent) writeAsk(id *api.Identity) (err error) {
147143
path := "/tmp/ask.sh"

0 commit comments

Comments
 (0)