update depreacted ioutil call

pull/179/head
Vit Listik 3 years ago
parent 2bd9f1e733
commit ca9b9fddf1
No known key found for this signature in database
GPG Key ID: DDDF5138DA46D76B
  1. 8
      cmd/daemon/dump.go
  2. 4
      cmd/daemon/record.go

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"github.com/curusarn/resh/internal/histcli" "github.com/curusarn/resh/internal/histcli"
"io/ioutil" "io"
"net/http" "net/http"
"github.com/curusarn/resh/internal/msg" "github.com/curusarn/resh/internal/msg"
@ -18,17 +18,17 @@ type dumpHandler struct {
func (h *dumpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *dumpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sugar := h.sugar.With(zap.String("endpoint", "/dump")) sugar := h.sugar.With(zap.String("endpoint", "/dump"))
sugar.Debugw("Handling request, reading body ...") sugar.Debugw("Handling request, reading body ...")
jsn, err := ioutil.ReadAll(r.Body) jsn, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
sugar.Errorw("Error reading body", "error", err) sugar.Errorw("Error reading body", "error", err)
return return
} }
sugar.Debugw("Unmarshaling record ...") sugar.Debugw("Unmarshalling record ...")
mess := msg.CliMsg{} mess := msg.CliMsg{}
err = json.Unmarshal(jsn, &mess) err = json.Unmarshal(jsn, &mess)
if err != nil { if err != nil {
sugar.Errorw("Error during unmarshaling", sugar.Errorw("Error during unmarshalling",
"error", err, "error", err,
"payload", jsn, "payload", jsn,
) )

@ -2,7 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"github.com/curusarn/resh/internal/recordint" "github.com/curusarn/resh/internal/recordint"
@ -25,7 +25,7 @@ func (h *recordHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sugar := h.sugar.With(zap.String("endpoint", "/record")) sugar := h.sugar.With(zap.String("endpoint", "/record"))
sugar.Debugw("Handling request, sending response, reading body ...") sugar.Debugw("Handling request, sending response, reading body ...")
w.Write([]byte("OK\n")) w.Write([]byte("OK\n"))
jsn, err := ioutil.ReadAll(r.Body) jsn, err := io.ReadAll(r.Body)
// run rest of the handler as goroutine to prevent any hangups // run rest of the handler as goroutine to prevent any hangups
go func() { go func() {
if err != nil { if err != nil {

Loading…
Cancel
Save