run gofumpt

This commit is contained in:
Matthew Penner 2021-11-15 10:37:56 -07:00
parent 43d66d14b2
commit 04b9ef69a1
No known key found for this signature in database
GPG Key ID: BAB67850901908A8
17 changed files with 34 additions and 36 deletions

View File

@ -456,7 +456,7 @@ func FromFile(path string) error {
return err
}
if err := yaml.Unmarshal([]byte(b), c); err != nil {
if err := yaml.Unmarshal(b, c); err != nil {
return err
}

View File

@ -31,7 +31,7 @@ type Allocations struct {
//
// You'll want to use DockerBindings() if you need to re-map 127.0.0.1 to the Docker interface.
func (a *Allocations) Bindings() nat.PortMap {
var out = nat.PortMap{}
out := nat.PortMap{}
for ip, ports := range a.Mappings {
for _, port := range ports {
@ -94,7 +94,7 @@ func (a *Allocations) DockerBindings() nat.PortMap {
// To accomplish this, we'll just get the values from "DockerBindings" and then set them
// to empty structs. Because why not.
func (a *Allocations) Exposed() nat.PortSet {
var out = nat.PortSet{}
out := nat.PortSet{}
for port := range a.DockerBindings() {
out[port] = struct{}{}

View File

@ -14,8 +14,10 @@ import (
"github.com/pterodactyl/wings/config"
)
var _conce sync.Once
var _client *client.Client
var (
_conce sync.Once
_client *client.Client
)
// Docker returns a docker client to be used throughout the codebase. Once a
// client has been created it will be returned for all subsequent calls to this

View File

@ -114,7 +114,6 @@ func (e *Environment) Events() *events.EventBus {
// ID auto-assigned when the container is created.
func (e *Environment) Exists() (bool, error) {
_, err := e.client.ContainerInspect(context.Background(), e.Id)
if err != nil {
// If this error is because the container instance wasn't found via Docker we
// can safely ignore the error and just return false.

View File

@ -15,9 +15,11 @@ import (
"github.com/mattn/go-colorable"
)
var Default = New(os.Stderr, true)
var bold = color2.New(color2.Bold)
var boldred = color2.New(color2.Bold, color2.FgRed)
var (
Default = New(os.Stderr, true)
bold = color2.New(color2.Bold)
boldred = color2.New(color2.Bold, color2.FgRed)
)
var Strings = [...]string{
log.DebugLevel: "DEBUG",

View File

@ -57,8 +57,7 @@ func (re *RequestError) StatusCode() int {
return re.response.StatusCode
}
type SftpInvalidCredentialsError struct {
}
type SftpInvalidCredentialsError struct{}
func (ice SftpInvalidCredentialsError) Error() string {
return "the credentials provided were invalid"

View File

@ -87,7 +87,6 @@ func TestPost(t *testing.T) {
}
c, _ := createTestClient(func(rw http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
})
r, err := c.Post(context.Background(), "/test", test)
assert.NoError(t, err)

View File

@ -35,7 +35,6 @@ func (h *Handler) registerListenerEvents(ctx context.Context) {
go h.listenForExpiration(ctx)
}
// ListenForExpiration checks the time to expiration on the JWT every 30 seconds
// until the token has expired. If we are within 3 minutes of the token expiring,
// send a notice over the socket that it is expiring soon. If it has expired,

View File

@ -12,8 +12,7 @@ var (
ErrServerIsRestoring = errors.New("server is currently being restored")
)
type crashTooFrequent struct {
}
type crashTooFrequent struct{}
func (e *crashTooFrequent) Error() string {
return "server has crashed too soon after the last detected crash"
@ -25,8 +24,7 @@ func IsTooFrequentCrashError(err error) bool {
return ok
}
type serverDoesNotExist struct {
}
type serverDoesNotExist struct{}
func (e *serverDoesNotExist) Error() string {
return "server does not exist on remote system"

View File

@ -45,7 +45,7 @@ type Archive struct {
// Create creates an archive at dst with all of the files defined in the
// included files struct.
func (a *Archive) Create(dst string) error {
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return err
}

View File

@ -85,7 +85,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
if err != nil {
return nil, err
}
f, err := os.OpenFile(cleaned, flag, 0644)
f, err := os.OpenFile(cleaned, flag, 0o644)
if err == nil {
return f, nil
}
@ -97,7 +97,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
if _, err := os.Stat(filepath.Dir(cleaned)); errors.Is(err, os.ErrNotExist) {
// Create the path leading up to the file we're trying to create, setting the final perms
// on it as we go.
if err := os.MkdirAll(filepath.Dir(cleaned), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(cleaned), 0o755); err != nil {
return nil, errors.Wrap(err, "server/filesystem: touch: failed to create directory tree")
}
if err := fs.Chown(filepath.Dir(cleaned)); err != nil {
@ -107,7 +107,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
o := &fileOpener{}
// Try to open the file now that we have created the pathing necessary for it, and then
// Chown that file so that the permissions don't mess with things.
f, err = o.open(cleaned, flag, 0644)
f, err = o.open(cleaned, flag, 0o644)
if err != nil {
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file with wait")
}
@ -181,7 +181,7 @@ func (fs *Filesystem) CreateDirectory(name string, p string) error {
if err != nil {
return err
}
return os.MkdirAll(cleaned, 0755)
return os.MkdirAll(cleaned, 0o755)
}
// Moves (or renames) a file or directory.
@ -210,7 +210,7 @@ func (fs *Filesystem) Rename(from string, to string) error {
// Ensure that the directory we're moving into exists correctly on the system. Only do this if
// we're not at the root directory level.
if d != fs.Path() {
if mkerr := os.MkdirAll(d, 0755); mkerr != nil {
if mkerr := os.MkdirAll(d, 0o755); mkerr != nil {
return errors.WithMessage(mkerr, "failed to create directory structure for file rename")
}
}
@ -377,7 +377,7 @@ func (fs *Filesystem) TruncateRootDirectory() error {
if err := os.RemoveAll(fs.Path()); err != nil {
return err
}
if err := os.Mkdir(fs.Path(), 0755); err != nil {
if err := os.Mkdir(fs.Path(), 0o755); err != nil {
return err
}
atomic.StoreInt64(&fs.diskUsed, 0)
@ -485,7 +485,7 @@ func (fs *Filesystem) ListDirectory(p string) ([]Stat, error) {
defer wg.Done()
var m *mimetype.MIME
var d = "inode/directory"
d := "inode/directory"
if !f.IsDir() {
cleanedp := filepath.Join(cleaned, f.Name())
if f.Mode()&os.ModeSymlink != 0 {

View File

@ -115,8 +115,8 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
var cleaned []string
// Simple locker function to avoid racy appends to the array of cleaned paths.
var m = new(sync.Mutex)
var push = func(c string) {
m := new(sync.Mutex)
push := func(c string) {
m.Lock()
cleaned = append(cleaned, c)
m.Unlock()

View File

@ -107,7 +107,7 @@ func TestFilesystem_Blocks_Symlinks(t *testing.T) {
panic(err)
}
if err := os.Mkdir(filepath.Join(rfs.root, "/malicious_dir"), 0777); err != nil {
if err := os.Mkdir(filepath.Join(rfs.root, "/malicious_dir"), 0o777); err != nil {
panic(err)
}

View File

@ -215,11 +215,11 @@ func (ip *InstallationProcess) tempDir() string {
func (ip *InstallationProcess) writeScriptToDisk() error {
// Make sure the temp directory root exists before trying to make a directory within it. The
// ioutil.TempDir call expects this base to exist, it won't create it for you.
if err := os.MkdirAll(ip.tempDir(), 0700); err != nil {
if err := os.MkdirAll(ip.tempDir(), 0o700); err != nil {
return errors.WithMessage(err, "could not create temporary directory for install process")
}
f, err := os.OpenFile(filepath.Join(ip.tempDir(), "install.sh"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
f, err := os.OpenFile(filepath.Join(ip.tempDir(), "install.sh"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
return errors.WithMessage(err, "failed to write server installation script to disk before mount")
}
@ -350,7 +350,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
return err
}
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return err
}
@ -516,7 +516,6 @@ func (ip *InstallationProcess) StreamOutput(ctx context.Context, id string) erro
ShowStderr: true,
Follow: true,
})
if err != nil {
return err
}

View File

@ -59,7 +59,6 @@ func (s *Server) StartEventListeners() {
err := t.Increment(func() {
s.PublishConsoleOutputFromDaemon("Your server is outputting too much data and is being throttled.")
})
// An error is only returned if the server has breached the thresholds set.
if err != nil {
// If the process is already stopping, just let it continue with that action rather than attempting

View File

@ -15,8 +15,10 @@ import (
"emperror.dev/errors"
)
var cr = []byte(" \r")
var crr = []byte("\r\n")
var (
cr = []byte(" \r")
crr = []byte("\r\n")
)
// FirstNotEmpty returns the first string passed in that is not an empty value.
func FirstNotEmpty(v ...string) string {