diff --git a/config/config.go b/config/config.go index 44ad8a0..a560f58 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,7 @@ package config import ( "bytes" "fmt" - "io/ioutil" + "io" "os" "runtime" "strconv" @@ -34,7 +34,7 @@ func writeConfig() { } if _, err := os.Stat(prefConfigLocation); os.IsNotExist(err) { - if err = os.MkdirAll(prefConfigLocation, 0755); err != nil { + if err = os.MkdirAll(prefConfigLocation, 0o755); err != nil { println("error writing new config: " + err.Error()) os.Exit(1) } @@ -136,11 +136,8 @@ func setConfigFileLocations() { configLocations = append(configLocations, "./") if runtime.GOOS != "windows" { - configLocations = append(configLocations, prefConfigLocation) - configLocations = append(configLocations, "/etc/"+Title+"/") - configLocations = append(configLocations, "../") - configLocations = append(configLocations, "../../") - + configLocations = append(configLocations, + prefConfigLocation, "/etc/"+Title+"/", "../", "../../") } } @@ -149,7 +146,7 @@ func loadCustomConfig(path string) { println("Error opening specified config file: " + path) panic("config file open fatal error: " + err.Error()) } - buf, err := ioutil.ReadAll(f) + buf, err := io.ReadAll(f) err2 := snek.ReadConfig(bytes.NewBuffer(buf)) switch { case err != nil: @@ -183,9 +180,7 @@ func argParse() { noColorForce = true case "--banner": BannerOnly = true - case "--config": - fallthrough - case "-c": + case "-c", "--config": if len(os.Args) <= i-1 { panic("syntax error! expected file after -c") } diff --git a/config/logger.go b/config/logger.go index a2c1373..f390c6f 100644 --- a/config/logger.go +++ b/config/logger.go @@ -21,7 +21,7 @@ var ( func StartLogger() zerolog.Logger { logDir = snek.GetString("logger.directory") if !strings.HasSuffix(logDir, "/") { - logDir = logDir + "/" + logDir += "/" } if err := os.MkdirAll(logDir, os.ModePerm); err != nil { println("cannot create log directory: " + logDir + "(" + err.Error() + ")") @@ -31,14 +31,14 @@ func StartLogger() zerolog.Logger { logFileName := "HellPot" if snek.GetBool("logger.use_date_filename") { - tn := strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1) - tn = strings.Replace(logFileName, ":", "-", -1) + tn := strings.ReplaceAll(time.Now().Format(time.RFC822), " ", "_") + tn = strings.ReplaceAll(logFileName, ":", "-") logFileName = logFileName + "_" + tn } CurrentLogFile = logDir + logFileName + ".log" - if logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil { + if logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666); err != nil { println("cannot create log file: " + err.Error()) os.Exit(1) } diff --git a/extra/banner.go b/extra/banner.go index 59d855e..e86555b 100644 --- a/extra/banner.go +++ b/extra/banner.go @@ -7,7 +7,7 @@ import ( "encoding/base64" "encoding/binary" "fmt" - "io/ioutil" + "io" "strings" "github.com/yunginnanet/HellPot/config" @@ -43,13 +43,13 @@ func process(in string) (s string) { for n := 1; n < 5; n++ { s = cproc(s, fmt.Sprintf("%d", n)) } - s = strings.Replace(s, "$maj", maj, -1) - s = strings.Replace(s, "$min", min, -1) + s = strings.ReplaceAll(s, "$maj", maj) + s = strings.ReplaceAll(s, "$min", min) return } func gz(data []byte) string { gz, err1 := gzip.NewReader(bytes.NewReader(data)) - out, err2 := ioutil.ReadAll(gz) + out, err2 := io.ReadAll(gz) if err1 != nil || err2 != nil { bannerFail(err1, err2) } diff --git a/heffalump/heffalump.go b/heffalump/heffalump.go index 8aa8103..49ba776 100644 --- a/heffalump/heffalump.go +++ b/heffalump/heffalump.go @@ -62,7 +62,7 @@ func (h *Heffalump) WriteHell(bw *bufio.Writer) (int64, error) { buf := h.getBuffer() defer h.putBuffer(buf) - if _, err = io.WriteString(bw, "\n\n"); err != nil { + if _, err = bw.WriteString("\n\n"); err != nil { return n, err } diff --git a/heffalump/util.go b/heffalump/util.go index a911c37..7a4cf9b 100644 --- a/heffalump/util.go +++ b/heffalump/util.go @@ -4,7 +4,7 @@ import ( "bytes" "compress/gzip" "encoding/base64" - "io/ioutil" + "io" ) func gz(data []byte) string { @@ -12,7 +12,7 @@ func gz(data []byte) string { if err != nil { panic(err) } - out, err := ioutil.ReadAll(gz) + out, err := io.ReadAll(gz) if err != nil { panic(err) } diff --git a/http/router_unix.go b/http/router_unix.go index 995ffa6..b4fe111 100644 --- a/http/router_unix.go +++ b/http/router_unix.go @@ -24,7 +24,7 @@ func listenOnUnixSocket(addr string, r *router.Router) error { _ = syscall.Unlink(addr) // Before we set socket permissions, we want to make sure only the user HellPot is running under // has permission to the socket. - oldmask := syscall.Umask(0077) + oldmask := syscall.Umask(0o077) unixListener, err = net.ListenUnix("unix", unixAddr) syscall.Umask(oldmask) if err == nil {