From ef32197fef427f3e78164f38f9270c4992fa196c Mon Sep 17 00:00:00 2001 From: Shengqi Chen Date: Sat, 11 Jan 2025 16:00:34 +0800 Subject: [PATCH] Run go fmt Signed-off-by: Shengqi Chen --- cmd/tunasync/tunasync.go | 6 +++--- tests/httpClient.go | 1 + tests/httpServer.go | 1 + tests/managerMain.go | 1 + tests/workerMain.go | 1 + worker/btrfs_snapshot_hook.go | 1 + worker/btrfs_snapshot_hook_nolinux.go | 1 + worker/config.go | 4 ++-- worker/docker.go | 12 ++++++------ worker/job.go | 10 ++++++---- worker/rsync_provider.go | 2 +- worker/runner.go | 12 ++++++------ 12 files changed, 30 insertions(+), 22 deletions(-) diff --git a/cmd/tunasync/tunasync.go b/cmd/tunasync/tunasync.go index 86a701b..44a7390 100644 --- a/cmd/tunasync/tunasync.go +++ b/cmd/tunasync/tunasync.go @@ -9,10 +9,10 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/pkg/profile" - "gopkg.in/op/go-logging.v1" - "github.com/urfave/cli" "github.com/moby/moby/pkg/reexec" + "github.com/pkg/profile" + "github.com/urfave/cli" + "gopkg.in/op/go-logging.v1" tunasync "github.com/tuna/tunasync/internal" "github.com/tuna/tunasync/manager" diff --git a/tests/httpClient.go b/tests/httpClient.go index b719282..e143b14 100644 --- a/tests/httpClient.go +++ b/tests/httpClient.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/tests/httpServer.go b/tests/httpServer.go index 45ab892..700806e 100644 --- a/tests/httpServer.go +++ b/tests/httpServer.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/tests/managerMain.go b/tests/managerMain.go index 0f6033b..58644fa 100644 --- a/tests/managerMain.go +++ b/tests/managerMain.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/tests/workerMain.go b/tests/workerMain.go index 61ed926..c4afca7 100644 --- a/tests/workerMain.go +++ b/tests/workerMain.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package main diff --git a/worker/btrfs_snapshot_hook.go b/worker/btrfs_snapshot_hook.go index f48262c..4eb81ff 100644 --- a/worker/btrfs_snapshot_hook.go +++ b/worker/btrfs_snapshot_hook.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package worker diff --git a/worker/btrfs_snapshot_hook_nolinux.go b/worker/btrfs_snapshot_hook_nolinux.go index aae4c53..8d4c160 100644 --- a/worker/btrfs_snapshot_hook_nolinux.go +++ b/worker/btrfs_snapshot_hook_nolinux.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package worker diff --git a/worker/config.go b/worker/config.go index c91cbc2..2b5a614 100644 --- a/worker/config.go +++ b/worker/config.go @@ -6,10 +6,10 @@ import ( "path/filepath" "github.com/BurntSushi/toml" - "github.com/imdario/mergo" - units "github.com/docker/go-units" cgv1 "github.com/containerd/cgroups" cgv2 "github.com/containerd/cgroups/v2" + units "github.com/docker/go-units" + "github.com/imdario/mergo" ) type providerEnum uint8 diff --git a/worker/docker.go b/worker/docker.go index ae8cf77..f115f97 100644 --- a/worker/docker.go +++ b/worker/docker.go @@ -10,9 +10,9 @@ import ( type dockerHook struct { emptyHook - image string - volumes []string - options []string + image string + volumes []string + options []string memoryLimit MemBytes } @@ -33,9 +33,9 @@ func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dock emptyHook: emptyHook{ provider: p, }, - image: mCfg.DockerImage, - volumes: volumes, - options: options, + image: mCfg.DockerImage, + volumes: volumes, + options: options, memoryLimit: mCfg.MemoryLimit, } } diff --git a/worker/job.go b/worker/job.go index 39af616..536ae15 100644 --- a/worker/job.go +++ b/worker/job.go @@ -87,10 +87,12 @@ func (m *mirrorJob) SetProvider(provider mirrorProvider) error { // runMirrorJob is the goroutine where syncing job runs in // arguments: -// provider: mirror provider object -// ctrlChan: receives messages from the manager -// managerChan: push messages to the manager, this channel should have a larger buffer -// sempaphore: make sure the concurrent running syncing job won't explode +// +// provider: mirror provider object +// ctrlChan: receives messages from the manager +// managerChan: push messages to the manager, this channel should have a larger buffer +// sempaphore: make sure the concurrent running syncing job won't explode +// // TODO: message struct for managerChan func (m *mirrorJob) Run(managerChan chan<- jobMessage, semaphore chan empty) error { jobsDone.Add(1) diff --git a/worker/rsync_provider.go b/worker/rsync_provider.go index fc9b451..27ca7fc 100644 --- a/worker/rsync_provider.go +++ b/worker/rsync_provider.go @@ -67,7 +67,7 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) { options := []string{ "-aHvh", "--no-o", "--no-g", "--stats", - "--filter" , "risk .~tmp~/", "--exclude", ".~tmp~/", + "--filter", "risk .~tmp~/", "--exclude", ".~tmp~/", "--delete", "--delete-after", "--delay-updates", "--safe-links", } diff --git a/worker/runner.go b/worker/runner.go index 5f25a84..ac3aadc 100644 --- a/worker/runner.go +++ b/worker/runner.go @@ -11,9 +11,9 @@ import ( "time" "github.com/codeskyblue/go-sh" - "golang.org/x/sys/unix" - "github.com/moby/moby/pkg/reexec" cgv1 "github.com/containerd/cgroups" + "github.com/moby/moby/pkg/reexec" + "golang.org/x/sys/unix" ) // runner is to run os commands giving command line, env and log file @@ -60,7 +60,7 @@ func newCmdJob(provider mirrorProvider, cmdAndArgs []string, workingDir string, } // set memlimit if d.memoryLimit != 0 { - args = append(args, "-m", fmt.Sprint(d.memoryLimit.Value())) + args = append(args, "-m", fmt.Sprint(d.memoryLimit.Value())) } // apply options args = append(args, d.options...) @@ -115,7 +115,7 @@ func (c *cmdJob) Start() error { if cg != nil { logger.Debugf("Preparing cgroup sync pipes for job %s", c.provider.Name()) var err error - pipeR, pipeW, err = os.Pipe(); + pipeR, pipeW, err = os.Pipe() if err != nil { return err } @@ -139,7 +139,7 @@ func (c *cmdJob) Start() error { } pid := c.cmd.Process.Pid if cg.cgCfg.isUnified { - if err := cg.cgMgrV2.AddProc(uint64(pid)); err != nil{ + if err := cg.cgMgrV2.AddProc(uint64(pid)); err != nil { if errors.Is(err, syscall.ESRCH) { logger.Infof("Write pid %d to cgroup failed: process vanished, ignoring") } else { @@ -147,7 +147,7 @@ func (c *cmdJob) Start() error { } } } else { - if err := cg.cgMgrV1.Add(cgv1.Process{Pid: pid}); err != nil{ + if err := cg.cgMgrV1.Add(cgv1.Process{Pid: pid}); err != nil { if errors.Is(err, syscall.ESRCH) { logger.Infof("Write pid %d to cgroup failed: process vanished, ignoring") } else {