internal: replace ioutils

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-08 21:00:45 +02:00
parent 7ea0b4b9e4
commit 6356ddd9f3
3 changed files with 10 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package config
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"reflect"
@ -62,7 +61,7 @@ func (c *Config) Setup(paths ...string) {
}
func (c *Config) LoadConfig(path string) error {
raw, err := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("Failed to load config file: %w", err)
}
@ -129,7 +128,7 @@ func (c *Config) parseScheme(rawVal string) string {
}
return u.RawQuery
} else if u.Scheme == "file" {
d, err := ioutil.ReadFile(u.Path)
d, err := os.ReadFile(u.Path)
if err != nil {
return u.RawQuery
}

View File

@ -1,7 +1,7 @@
package web
import (
"io/ioutil"
"io"
"net/http"
"github.com/gorilla/mux"
@ -43,12 +43,7 @@ func RunMetricsServer() {
l.WithError(err).Warning("failed to get upstream metrics")
return
}
bm, err := ioutil.ReadAll(res.Body)
if err != nil {
l.WithError(err).Warning("failed to get upstream metrics")
return
}
_, err = rw.Write(bm)
_, err = io.Copy(rw, res.Body)
if err != nil {
l.WithError(err).Warning("failed to get upstream metrics")
return

View File

@ -1,8 +1,9 @@
package web
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strings"
@ -19,13 +20,14 @@ func (ws *WebServer) APISentryProxy(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusBadRequest)
return
}
fullBody, err := ioutil.ReadAll(r.Body)
fb := &bytes.Buffer{}
_, err := io.Copy(fb, r.Body)
if err != nil {
ws.log.Debug("failed to read body")
rw.WriteHeader(http.StatusBadRequest)
return
}
lines := strings.Split(string(fullBody), "\n")
lines := strings.Split(string(fb.Bytes()), "\n")
if len(lines) < 1 {
rw.WriteHeader(http.StatusBadRequest)
return
@ -42,7 +44,7 @@ func (ws *WebServer) APISentryProxy(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusBadRequest)
return
}
res, err := http.DefaultClient.Post("https://sentry.beryju.org/api/8/envelope/", "application/octet-stream", strings.NewReader(string(fullBody)))
res, err := http.DefaultClient.Post("https://sentry.beryju.org/api/8/envelope/", "application/octet-stream", fb)
if err != nil {
ws.log.WithError(err).Warning("failed to proxy sentry")
rw.WriteHeader(http.StatusBadRequest)