Skip to content

Commit 831ab75

Browse files
committed
reformat go code
- gofmt -w pkg - gofmt -w cmd
1 parent beffa7d commit 831ab75

File tree

21 files changed

+109
-143
lines changed

21 files changed

+109
-143
lines changed

cmd/zfs-snap-diff/main.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import (
55
"fmt"
66
"github.com/j-keck/plog"
77
"github.com/j-keck/zfs-snap-diff/pkg/config"
8+
"github.com/j-keck/zfs-snap-diff/pkg/fs"
89
"github.com/j-keck/zfs-snap-diff/pkg/webapp"
910
"github.com/j-keck/zfs-snap-diff/pkg/zfs"
1011
"os"
1112
"strings"
12-
"github.com/j-keck/zfs-snap-diff/pkg/fs"
1313
)
1414

1515
var version string = "SNAPSHOT"
1616

1717
type CliConfig struct {
18-
logLevel plog.LogLevel
19-
logTimestamps bool
20-
logLocations bool
21-
printVersion bool
18+
logLevel plog.LogLevel
19+
logTimestamps bool
20+
logLocations bool
21+
printVersion bool
2222
listenOnAllInterfaces bool
2323
}
2424

@@ -54,7 +54,7 @@ func main() {
5454
fmt.Fprintf(os.Stderr, "\nABORT:\n paramter <ZFS_DATASET_NAME> missing\n")
5555
if datasetNames, err := zfs.AvailableDatasetNames(); err == nil {
5656
names := strings.Join(datasetNames, " | ")
57-
fmt.Fprintf(os.Stderr, "\nUSAGE:\n %s [OPTIONS] <ZFS_DATASET_NAME>\n\n", zfsSnapDiffBin)
57+
fmt.Fprintf(os.Stderr, "\nUSAGE:\n %s [OPTIONS] <ZFS_DATASET_NAME>\n\n", zfsSnapDiffBin)
5858
fmt.Fprintf(os.Stderr, " <ZFS_DATASET_NAMES>: %s\n\n", names)
5959
} else {
6060
fmt.Fprintf(os.Stderr, "\nUSAGE:\n %s [OPTIONS] <ZFS_DATASET_NAME>\n\n", zfsSnapDiffBin)
@@ -63,7 +63,6 @@ func main() {
6363
return
6464
}
6565

66-
6766
if z, err := zfs.NewZFS(datasetName); err == nil {
6867
webapp := webapp.NewWebApp(z)
6968
if err := webapp.Start(); err != nil {
@@ -74,7 +73,6 @@ func main() {
7473
fmt.Fprintf(os.Stderr, err.Error())
7574
}
7675

77-
7876
}
7977

8078
func parseFlags() CliConfig {
@@ -131,7 +129,6 @@ func loadConfig() {
131129
config.LoadConfig(configPath)
132130
}
133131

134-
135132
func initLogger() {
136133
consoleLogger := plog.NewConsoleLogger(" | ")
137134
consoleLogger.AddLogFormatter(plog.Level)

cmd/zsd/cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

33
import (
4-
"github.com/j-keck/zfs-snap-diff/pkg/scanner"
54
"encoding/json"
6-
"github.com/j-keck/zfs-snap-diff/pkg/fs"
7-
"os"
85
"errors"
96
"fmt"
7+
"github.com/j-keck/zfs-snap-diff/pkg/fs"
8+
"github.com/j-keck/zfs-snap-diff/pkg/scanner"
9+
"os"
1010
)
1111

1212
func cacheFileVersions(versions []scanner.FileVersion) error {

cmd/zsd/main.go

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package main
22

33
import (
4-
"github.com/j-keck/zfs-snap-diff/pkg/zfs"
4+
"errors"
5+
"flag"
6+
"fmt"
7+
"github.com/j-keck/plog"
8+
"github.com/j-keck/zfs-snap-diff/pkg/config"
59
"github.com/j-keck/zfs-snap-diff/pkg/diff"
10+
"github.com/j-keck/zfs-snap-diff/pkg/fs"
611
"github.com/j-keck/zfs-snap-diff/pkg/scanner"
7-
"github.com/j-keck/plog"
12+
"github.com/j-keck/zfs-snap-diff/pkg/zfs"
13+
"math"
814
"os"
915
"path/filepath"
10-
"fmt"
11-
"time"
12-
"flag"
13-
"math"
14-
"strings"
1516
"strconv"
16-
"errors"
17-
"github.com/j-keck/zfs-snap-diff/pkg/config"
18-
"github.com/j-keck/zfs-snap-diff/pkg/fs"
17+
"strings"
18+
"time"
1919
)
2020

2121
var version string = "SNAPSHOT"
@@ -34,14 +34,13 @@ func main() {
3434
flag.PrintDefaults()
3535
fmt.Fprintf(os.Stderr, "\nACTIONS:\n")
3636
fmt.Fprintf(os.Stderr, " list : list zfs snapshots where the given file was modified\n")
37-
fmt.Fprintf(os.Stderr, " cat <#|SNAPSHOT>: show the file content from the given snapshot\n");
37+
fmt.Fprintf(os.Stderr, " cat <#|SNAPSHOT>: show the file content from the given snapshot\n")
3838
fmt.Fprintf(os.Stderr, " diff <#|SNAPSHOT>: show a diff from the selected snapshot to the actual version\n")
3939
fmt.Fprintf(os.Stderr, " restore <#|SNAPSHOT>: restore the file from the given snapshot\n")
4040
fmt.Fprintf(os.Stderr, "\nYou can use the snapshot number from the `list` output or the snapshot name to select a snapshot.\n")
4141
fmt.Fprintf(os.Stderr, "\nProject home page: https://j-keck.github.io/zfs-snap-diff\n")
4242
}
4343

44-
4544
initLogger()
4645
cliCfg := parseFlags()
4746
log := reconfigureLogger(cliCfg)
@@ -56,7 +55,6 @@ func main() {
5655
return
5756
}
5857

59-
6058
// file path
6159
fileName := flag.Arg(0)
6260
filePath, err := filepath.Abs(fileName)
@@ -66,7 +64,6 @@ func main() {
6664
}
6765
log.Debugf("full path: %s", filePath)
6866

69-
7067
// init zfs handler
7168
zfs, ds, err := zfs.NewZFSForFilePath(filePath)
7269
if err != nil {
@@ -75,8 +72,7 @@ func main() {
7572
}
7673
log.Debugf("work on dataset: %s", ds.Name)
7774

78-
79-
// action
75+
// action
8076
action := flag.Arg(1)
8177
switch action {
8278
case "list":
@@ -120,7 +116,7 @@ func main() {
120116
}
121117

122118
file, err := fs.GetFileHandle(version.Backup.Path)
123-
if err !=nil {
119+
if err != nil {
124120
log.Errorf("unable to find file in the snapshot - %v", err)
125121
return
126122
}
@@ -168,7 +164,6 @@ func main() {
168164
return
169165
}
170166

171-
172167
backupPath, err := version.Actual.Backup()
173168
if err != nil {
174169
log.Errorf("unable to backup the acutal version - %v", err)
@@ -186,7 +181,6 @@ func main() {
186181
}
187182
}
188183

189-
190184
func lookupRequestedVersion(filePath, versionName string) (*scanner.FileVersion, error) {
191185

192186
// load file-versions from cache file
@@ -195,7 +189,6 @@ func lookupRequestedVersion(filePath, versionName string) (*scanner.FileVersion,
195189
return nil, err
196190
}
197191

198-
199192
// `versionName` can be the snapshot number from the `list` output or the name
200193
var version *scanner.FileVersion
201194
if idx, err := strconv.Atoi(versionName); err == nil {
@@ -223,7 +216,6 @@ func lookupRequestedVersion(filePath, versionName string) (*scanner.FileVersion,
223216
}
224217
}
225218

226-
227219
func humanDuration(dur time.Duration) string {
228220
s := int(dur.Seconds())
229221
if s < 60 {

pkg/config/config.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
package config
22

33
import (
4-
"github.com/j-keck/plog"
5-
"github.com/BurntSushi/toml"
64
"bytes"
5+
"github.com/BurntSushi/toml"
6+
"github.com/j-keck/plog"
77
"io/ioutil"
88
)
99

1010
var log = plog.GlobalLogger()
1111

1212
var Get Config = Config{
13-
Webserver: NewDefaultWebserverConfig(),
14-
ZFS: NewDefaultZFSConfig(),
15-
UseCacheDirForBackups: true,
16-
DaysToScan: 2,
13+
Webserver: NewDefaultWebserverConfig(),
14+
ZFS: NewDefaultZFSConfig(),
15+
UseCacheDirForBackups: true,
16+
DaysToScan: 2,
1717
MaxArchiveUnpackedSizeMB: 200,
18-
SnapshotNameTemplate: "zfs-snap-diff-%FT%H:%M",
19-
CompareMethod: "auto",
20-
DiffContextSize: 5,
18+
SnapshotNameTemplate: "zfs-snap-diff-%FT%H:%M",
19+
CompareMethod: "auto",
20+
DiffContextSize: 5,
2121
}
2222

2323
type Config struct {
24-
Webserver WebserverConfig `toml:"webserver"`
25-
ZFS ZFSConfig `toml:"zfs"`
26-
UseCacheDirForBackups bool `toml:"use-cache-dir-for-backups"`
27-
DaysToScan int `toml:"days-to-scan"`
28-
MaxArchiveUnpackedSizeMB int `toml:"max-archive-unpacked-size-mb"`
29-
SnapshotNameTemplate string `toml:"snapshot-name-template"`
30-
CompareMethod string `toml:"compare-method"`
31-
DiffContextSize int `toml:"diff-context-size"`
24+
Webserver WebserverConfig `toml:"webserver"`
25+
ZFS ZFSConfig `toml:"zfs"`
26+
UseCacheDirForBackups bool `toml:"use-cache-dir-for-backups"`
27+
DaysToScan int `toml:"days-to-scan"`
28+
MaxArchiveUnpackedSizeMB int `toml:"max-archive-unpacked-size-mb"`
29+
SnapshotNameTemplate string `toml:"snapshot-name-template"`
30+
CompareMethod string `toml:"compare-method"`
31+
DiffContextSize int `toml:"diff-context-size"`
3232
}
3333

34-
3534
func LoadConfig(path string) {
3635
log.Debugf("load configuration from %s", path)
3736
if _, err := toml.DecodeFile(path, &Get); err != nil {
@@ -40,7 +39,6 @@ func LoadConfig(path string) {
4039
}
4140
}
4241

43-
4442
func SaveConfig(path string) error {
4543
buf := new(bytes.Buffer)
4644

pkg/config/webserver_config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66

77
type WebserverConfig struct {
88
// listen
9-
ListenIp string `toml:"listen-ip"`
10-
ListenPort int `toml:"listen-port"`
9+
ListenIp string `toml:"listen-ip"`
10+
ListenPort int `toml:"listen-port"`
1111

1212
// tls
13-
UseTLS bool `toml:"use-tls"`
14-
CertFile string `toml:"cert-file"`
15-
KeyFile string `toml:"key-file"`
13+
UseTLS bool `toml:"use-tls"`
14+
CertFile string `toml:"cert-file"`
15+
KeyFile string `toml:"key-file"`
1616
// webapp
17-
WebappDir string `toml:"webapp-dir,omitempty"`
17+
WebappDir string `toml:"webapp-dir,omitempty"`
1818
}
1919

2020
func (self *WebserverConfig) ListenAddress() string {
@@ -23,8 +23,8 @@ func (self *WebserverConfig) ListenAddress() string {
2323

2424
func NewDefaultWebserverConfig() WebserverConfig {
2525
return WebserverConfig{
26-
ListenIp: "127.0.0.1",
27-
ListenPort: 12345,
28-
UseTLS: false,
26+
ListenIp: "127.0.0.1",
27+
ListenPort: 12345,
28+
UseTLS: false,
2929
}
3030
}

pkg/fs/dir_handle.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package fs
22

33
import (
4+
"archive/zip"
5+
"fmt"
6+
"github.com/j-keck/zfs-snap-diff/pkg/config"
47
"io/ioutil"
58
"os"
69
"path/filepath"
7-
"archive/zip"
810
"strings"
9-
"github.com/j-keck/zfs-snap-diff/pkg/config"
10-
"fmt"
1111
)
1212

1313
// DirHandle represents a directory
@@ -27,7 +27,6 @@ func GetDirHandle(path string) (DirHandle, error) {
2727
return handle.AsDirHandle()
2828
}
2929

30-
3130
// GetOrCreateDirHandle returns a handle to a existing or a new created directory.
3231
func GetOrCreateDirHandle(path string, perm os.FileMode) (DirHandle, error) {
3332
if dir, err := GetDirHandle(path); err == nil {
@@ -45,7 +44,6 @@ func GetOrCreateDirHandle(path string, perm os.FileMode) (DirHandle, error) {
4544
}
4645
}
4746

48-
4947
// GetSubDirHandle returns a child-dir of the current dir-handle.
5048
// This operation fails if the requested directory does not exists.
5149
func (self *DirHandle) GetSubDirHandle(name string) (DirHandle, error) {
@@ -65,7 +63,6 @@ func (self *DirHandle) GetFileHandle(name string) (FileHandle, error) {
6563
return GetFileHandle(path)
6664
}
6765

68-
6966
// ReadFile reads a child-file of the current dir-handle.
7067
func (self *DirHandle) ReadFile(name string) ([]byte, error) {
7168
path := filepath.Join(self.Path, name)
@@ -113,14 +110,14 @@ func (self *DirHandle) CreateArchive(name string) (FileHandle, error) {
113110

114111
var add func(*FSHandle, string, *zip.Writer, *int) error
115112
add = func(h *FSHandle, basePath string, w *zip.Writer, archiveSize *int) error {
116-
if maxSizeMB > 0 && *archiveSize / 1024 / 1024 > maxSizeMB {
113+
if maxSizeMB > 0 && *archiveSize/1024/1024 > maxSizeMB {
117114
return fmt.Errorf("abort - maximum configured archive size reached (%dMB > %dMB)",
118-
*archiveSize / 1024 / 1024,
115+
*archiveSize/1024/1024,
119116
maxSizeMB)
120117
}
121118
switch h.Kind {
122119
case FILE:
123-
relPath := strings.TrimPrefix(h.Path, basePath + "/")
120+
relPath := strings.TrimPrefix(h.Path, basePath+"/")
124121
log.Tracef("add %s to archive", relPath)
125122
f, err := w.Create(relPath)
126123
if err != nil {

pkg/fs/dirs.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package fs
22

33
import (
4-
"path/filepath"
4+
"errors"
55
"os"
6+
"path/filepath"
67
"runtime"
7-
"errors"
88
)
99

10-
1110
// ConfigDir returns the user-local config directory
1211
func ConfigDir() (DirHandle, error) {
1312
// lookup base path - somethink like '$HOME/.config'
@@ -27,7 +26,7 @@ func ConfigDir() (DirHandle, error) {
2726
if basePath == "" {
2827
basePath = os.Getenv("HOME")
2928
if basePath == "" {
30-
return DirHandle{}, errors.New("neither $XDG_CONFIG_HOME nor $HOME are defined")
29+
return DirHandle{}, errors.New("neither $XDG_CONFIG_HOME nor $HOME are defined")
3130
}
3231
basePath += "/.config"
3332
}
@@ -50,7 +49,6 @@ func CacheDir() (DirHandle, error) {
5049
return GetOrCreateDirHandle(path, 0770)
5150
}
5251

53-
5452
// TempDir returns the directory for temporary files
5553
func TempDir() (DirHandle, error) {
5654
tempPath := os.TempDir()

0 commit comments

Comments
 (0)