internal: replace ioutils
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
7ea0b4b9e4
commit
6356ddd9f3
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -62,7 +61,7 @@ func (c *Config) Setup(paths ...string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) LoadConfig(path string) error {
|
func (c *Config) LoadConfig(path string) error {
|
||||||
raw, err := ioutil.ReadFile(path)
|
raw, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to load config file: %w", err)
|
return fmt.Errorf("Failed to load config file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -129,7 +128,7 @@ func (c *Config) parseScheme(rawVal string) string {
|
||||||
}
|
}
|
||||||
return u.RawQuery
|
return u.RawQuery
|
||||||
} else if u.Scheme == "file" {
|
} else if u.Scheme == "file" {
|
||||||
d, err := ioutil.ReadFile(u.Path)
|
d, err := os.ReadFile(u.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return u.RawQuery
|
return u.RawQuery
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -43,12 +43,7 @@ func RunMetricsServer() {
|
||||||
l.WithError(err).Warning("failed to get upstream metrics")
|
l.WithError(err).Warning("failed to get upstream metrics")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bm, err := ioutil.ReadAll(res.Body)
|
_, err = io.Copy(rw, res.Body)
|
||||||
if err != nil {
|
|
||||||
l.WithError(err).Warning("failed to get upstream metrics")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = rw.Write(bm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.WithError(err).Warning("failed to get upstream metrics")
|
l.WithError(err).Warning("failed to get upstream metrics")
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -19,13 +20,14 @@ func (ws *WebServer) APISentryProxy(rw http.ResponseWriter, r *http.Request) {
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fullBody, err := ioutil.ReadAll(r.Body)
|
fb := &bytes.Buffer{}
|
||||||
|
_, err := io.Copy(fb, r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ws.log.Debug("failed to read body")
|
ws.log.Debug("failed to read body")
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lines := strings.Split(string(fullBody), "\n")
|
lines := strings.Split(string(fb.Bytes()), "\n")
|
||||||
if len(lines) < 1 {
|
if len(lines) < 1 {
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
@ -42,7 +44,7 @@ func (ws *WebServer) APISentryProxy(rw http.ResponseWriter, r *http.Request) {
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
ws.log.WithError(err).Warning("failed to proxy sentry")
|
ws.log.WithError(err).Warning("failed to proxy sentry")
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
Reference in New Issue