Skip to content

Commit 6fd6445

Browse files
committed
Fix all goreportcard warnings
1 parent 12a5b06 commit 6fd6445

17 files changed

+70
-70
lines changed

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package debpkg
66

77
import (
88
"fmt"
9-
"io/ioutil"
109
"github.com/xor-gate/debpkg/internal/config"
10+
"io/ioutil"
1111
)
1212

1313
// Config loads settings from a depkg.yml specfile

config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package debpkg
66

77
import (
8+
"github.com/stretchr/testify/assert"
9+
"github.com/xor-gate/debpkg/internal/test"
810
"runtime"
911
"testing"
10-
"github.com/xor-gate/debpkg/internal/test"
11-
"github.com/stretchr/testify/assert"
1212
)
1313

1414
// TestExampleConfig verifies if the config example in the root is correctly loaded
@@ -105,5 +105,5 @@ func TestNonExistingConfig(t *testing.T) {
105105
deb := New()
106106
defer deb.Close()
107107

108-
assert.NotNil(t, deb.Config("/non/existant/config/file"))
108+
assert.NotNil(t, deb.Config("/non/existent/config/file"))
109109
}

constants.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ const (
3131
VcsTypeSubversion VcsType = "Svn" // Subversion
3232
)
3333

34+
// Default installation variables
3435
const (
35-
DefaultInstallPrefix = "/usr"
36-
DefaultBinDir = "bin"
37-
DefaultSbinDir = "sbin"
38-
DefaultSysConfDir = "etc"
39-
DefaultDataRootDir = "share"
36+
DefaultInstallPrefix = "/usr" // Default install Prefix
37+
DefaultBinDir = "bin" // Default binary directory
38+
DefaultSbinDir = "sbin" // Default sbin directory
39+
DefaultSysConfDir = "etc" // Default configuration directory
40+
DefaultDataRootDir = "share" // Default data root directory
4041
)
4142

42-
const debianPathSeparator = "/"
43-
const debianBinaryVersion = "2.0\n"
44-
const debianFileExtension = "deb"
43+
const debianPathSeparator = "/"
44+
const debianBinaryVersion = "2.0\n"
45+
const debianFileExtension = "deb"

control.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package debpkg
66

77
import (
8-
"io"
98
"fmt"
9+
"io"
1010
"math"
1111
"strings"
1212

@@ -193,14 +193,14 @@ func (deb *DebPkg) SetBuiltUsing(info string) {
193193

194194
// AddControlExtraString is the same as AddControlExtra except it uses a string input
195195
func (deb *DebPkg) AddControlExtraString(name, s string) error {
196-
return deb.control.tgz.AddFileFromBuffer(name, []byte(s));
196+
return deb.control.tgz.AddFileFromBuffer(name, []byte(s))
197197
}
198198

199199
// AddControlExtra allows the advanced user to add custom script to the control.tar.gz Typical usage is
200200
// for preinst, postinst, postrm, prerm: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
201201
// And: https://www.debian.org/doc/manuals/maint-guide/dother.en.html#maintscripts
202202
func (deb *DebPkg) AddControlExtra(name, filename string) error {
203-
return deb.control.tgz.AddFile(filename, name);
203+
return deb.control.tgz.AddFile(filename, name)
204204
}
205205

206206
// AddConffile adds a file to the conffiles so it is treated as configuration files. Configuration files are not
@@ -236,9 +236,9 @@ func (c *control) version() string {
236236
return c.info.version.full
237237
}
238238
return fmt.Sprintf("%d.%d.%d",
239-
c.info.version.major,
240-
c.info.version.minor,
241-
c.info.version.patch)
239+
c.info.version.major,
240+
c.info.version.minor,
241+
c.info.version.patch)
242242
}
243243

244244
func (c *control) size() int64 {

control_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
package debpkg
66

77
import (
8-
"testing"
9-
"github.com/xor-gate/debpkg/internal/test"
108
"github.com/stretchr/testify/assert"
9+
"github.com/xor-gate/debpkg/internal/test"
10+
"testing"
1111
)
1212

1313
// Test correct output of a empty control file when no DepPkg Set* functions are called
@@ -82,7 +82,6 @@ Description:
8282
// Set full version string, this will overwrite the set SetVersion{Major,Minor,Patch} string
8383
deb.SetVersion("7.8.9")
8484

85-
8685
controlExpectFullVersion := `Package: foobar
8786
Version: 7.8.9
8887
Architecture: amd64
@@ -203,7 +202,7 @@ func TestControlFileExtra(t *testing.T) {
203202
echo "hello world from debpkg"
204203
`
205204

206-
filepath, err := test.WriteTempFile(t.Name() + ".sh", script)
205+
filepath, err := test.WriteTempFile(t.Name()+".sh", script)
207206
assert.Nil(t, err)
208207

209208
deb.SetName("debpkg-control-file-extra")

data.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package debpkg
77
import (
88
"crypto/md5"
99
"fmt"
10+
"github.com/xor-gate/debpkg/internal/targzip"
1011
"io"
1112
"os"
12-
"strings"
1313
"path/filepath"
14-
"github.com/xor-gate/debpkg/internal/targzip"
14+
"strings"
1515
)
1616

1717
type data struct {
@@ -82,7 +82,7 @@ func (d *data) addFile(filename string, dest ...string) error {
8282

8383
d.addDirectoriesForFile(destfilename)
8484

85-
//
85+
//
8686
if err := d.tgz.AddFile(filename, dest...); err != nil {
8787
return err
8888
}

deb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ package debpkg
66

77
import (
88
"fmt"
9+
"github.com/xor-gate/debpkg/internal/targzip"
910
"os"
1011
"path/filepath"
11-
"github.com/xor-gate/debpkg/internal/targzip"
1212
)
1313

1414
// DebPkg holds data for a single debian package
@@ -41,7 +41,7 @@ func New() *DebPkg {
4141
}
4242

4343
deb.control.tgz = control
44-
deb.data.tgz = data
44+
deb.data.tgz = data
4545

4646
return deb
4747
}

debpkg_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package debpkg
66

77
import (
88
"fmt"
9+
"github.com/stretchr/testify/assert"
10+
"github.com/xor-gate/debpkg/internal/test"
911
"go/build"
1012
"os/exec"
1113
"testing"
12-
"github.com/xor-gate/debpkg/internal/test"
13-
"github.com/stretchr/testify/assert"
1414
)
1515

1616
// testWrite writes the deb package to a temporary file and verifies with native dpkg tool when available
@@ -87,8 +87,8 @@ func TestWriteError(t *testing.T) {
8787
assert.Equal(t, fmt.Errorf("empty package name"), deb.Write(""))
8888
}
8989

90-
// ExampleWrite demonstrates generating a simple package
91-
func ExampleWrite() {
90+
// ExampleDebPkgWrite demonstrates generating a simple package
91+
func ExampleDebPkg_Write() {
9292
tempfile := TempDir() + "/foobar.deb"
9393

9494
deb := New()
@@ -110,7 +110,7 @@ func ExampleWrite() {
110110
// Do something with tempfile other than removing it...
111111
}
112112

113-
// TestFilenameFromFullVersion verifies if the whole version string is correctly concatinated
113+
// TestFilenameFromFullVersion verifies if the whole version string is correctly calculated
114114
func TestFilenameFromFullVersion(t *testing.T) {
115115
deb := New()
116116
defer deb.Close()

digest.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
package debpkg
66

77
import (
8-
"os"
9-
"time"
108
"bytes"
119
"crypto"
1210
"crypto/md5"
1311
"crypto/sha1"
1412
"fmt"
1513
"hash"
1614
"io"
15+
"os"
16+
"time"
1717

1818
"golang.org/x/crypto/openpgp"
1919
"golang.org/x/crypto/openpgp/clearsign"
@@ -90,7 +90,7 @@ func digestCalcDataHash(in io.Reader, hash hash.Hash) (string, error) {
9090
if _, err := io.Copy(hash, in); err != nil {
9191
return "", err
9292
}
93-
return string(hash.Sum(result)),nil
93+
return string(hash.Sum(result)), nil
9494
}
9595

9696
// WriteSigned package with GPG entity
@@ -134,5 +134,3 @@ func (deb *DebPkg) WriteSigned(filename string, entity *openpgp.Entity) error {
134134
}
135135
return deb.createDebAr(filename)
136136
}
137-
138-

digest_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package debpkg
66

77
import (
8-
"testing"
9-
"golang.org/x/crypto/openpgp"
10-
"github.com/xor-gate/debpkg/internal/test"
118
"github.com/stretchr/testify/assert"
9+
"github.com/xor-gate/debpkg/internal/test"
10+
"golang.org/x/crypto/openpgp"
11+
"testing"
1212
)
1313

1414
var e *openpgp.Entity

installvar.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var vars map[string]string
1515
func init() {
1616
vars = make(map[string]string)
1717
vars["INSTALLPREFIX"] = DefaultInstallPrefix
18-
vars["BINDIR"] = DefaultBinDir
19-
vars["SBINDIR"] = DefaultSbinDir
20-
vars["SYSCONFDIR"] = DefaultSysConfDir
21-
vars["DATAROOTDIR"] = DefaultDataRootDir
18+
vars["BINDIR"] = DefaultBinDir
19+
vars["SBINDIR"] = DefaultSbinDir
20+
vars["SYSCONFDIR"] = DefaultSysConfDir
21+
vars["DATAROOTDIR"] = DefaultDataRootDir
2222
}
2323

2424
// SetVar sets a variable for use with config file
@@ -35,7 +35,7 @@ func GetVar(v string) string {
3535
}
3636

3737
// GetVarWithPrefix gets a variable and appends INSTALLPREFIX when the value doesn't start with "/"
38-
func GetVarWithPrefix(v string) string{
38+
func GetVarWithPrefix(v string) string {
3939
val := GetVar(v)
4040
if val == "" {
4141
return val
@@ -54,10 +54,10 @@ func ExpandVar(msg string) (string, error) {
5454
}
5555
env := struct {
5656
INSTALLPREFIX string
57-
BINDIR string
58-
SBINDIR string
59-
DATAROOTDIR string
60-
SYSCONFDIR string
57+
BINDIR string
58+
SBINDIR string
59+
DATAROOTDIR string
60+
SYSCONFDIR string
6161
}{
6262
INSTALLPREFIX: vars["INSTALLPREFIX"],
6363
BINDIR: GetVarWithPrefix("BINDIR"),
@@ -67,7 +67,7 @@ func ExpandVar(msg string) (string, error) {
6767
}
6868
buf := bytes.NewBuffer(nil)
6969
if err := tmpl.Execute(buf, env); err != nil {
70-
return "",err
70+
return "", err
7171
}
72-
return buf.String(),nil
72+
return buf.String(), nil
7373
}

installvar_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
package debpkg
66

77
import (
8-
"testing"
98
"github.com/stretchr/testify/assert"
9+
"testing"
1010
)
1111

1212
func TestVarInit(t *testing.T) {
13-
tvs := map[string]string {
13+
tvs := map[string]string{
1414
"INSTALLPREFIX": DefaultInstallPrefix,
1515
"BINDIR": DefaultBinDir,
1616
"SBINDIR": DefaultSbinDir,
@@ -24,7 +24,7 @@ func TestVarInit(t *testing.T) {
2424
}
2525

2626
func TestGetVarWithPrefix(t *testing.T) {
27-
tvs := map[string]string {
27+
tvs := map[string]string{
2828
"BINDIR": "/usr/bin",
2929
"SBINDIR": "/usr/sbin",
3030
"SYSCONFDIR": "/usr/etc", // FIXME should not be possible -> "/etc"
@@ -37,7 +37,7 @@ func TestGetVarWithPrefix(t *testing.T) {
3737
}
3838

3939
func TestExpandVarBinDir(t *testing.T) {
40-
tvs := map[string]string {
40+
tvs := map[string]string{
4141
"{{.BINDIR}}": "/usr/bin",
4242
"{{.SBINDIR}}": "/usr/sbin",
4343
"{{.SYSCONFDIR}}": "/usr/etc", // FIXME should not be possible -> "/etc"

internal/config/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ package config
66

77
import (
88
"fmt"
9-
"runtime"
109
"gopkg.in/yaml.v2"
10+
"runtime"
1111
)
1212

13+
// PkgSpecFile represents a single debian package
1314
type PkgSpecFile struct {
1415
Name string `yaml:"name"`
1516
Version string `yaml:"version"`
@@ -32,7 +33,8 @@ type PkgSpecFile struct {
3233
EmptyDirectories []string `yaml:"emptydirs,flow"`
3334
}
3435

35-
func PkgSpecFileUnmarshal(data []byte) (*PkgSpecFile, error){
36+
// PkgSpecFileUnmarshal loads the configuration data into a PkgSpecFile structure
37+
func PkgSpecFileUnmarshal(data []byte) (*PkgSpecFile, error) {
3638
cfg := &PkgSpecFile{
3739
Name: "unknown",
3840
Version: "0.1.0+dev",
@@ -49,8 +51,8 @@ func PkgSpecFileUnmarshal(data []byte) (*PkgSpecFile, error){
4951

5052
err := yaml.Unmarshal(data, &cfg)
5153
if err != nil {
52-
return nil,fmt.Errorf("problem unmarshaling config file: %v", err)
54+
return nil, fmt.Errorf("problem unmarshaling config file: %v", err)
5355
}
5456

55-
return cfg,nil
57+
return cfg, nil
5658
}

internal/targzip/targz.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func newWriter(wc io.WriteCloser) *TarGzip {
3939
func NewTempFile(dir string) (*TarGzip, error) {
4040
f, err := ioutil.TempFile(dir, "debpkg")
4141
if err != nil {
42-
return nil,err
42+
return nil, err
4343
}
4444

4545
t := newWriter(f)
4646
t.fileName = f.Name()
47-
return t,nil
47+
return t, nil
4848
}
4949

5050
// AddFile write a file from filename into dest
@@ -80,8 +80,8 @@ func (t *TarGzip) AddFile(filename string, dest ...string) error {
8080
}
8181

8282
hdr.Name = strings.Trim(hdr.Name, "/")
83-
hdr.Uid = 0
84-
hdr.Gid = 0
83+
hdr.Uid = 0
84+
hdr.Gid = 0
8585

8686
// write the header to the tarball archive
8787
if err := t.writeHeader(hdr); err != nil {

0 commit comments

Comments
 (0)