Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposes a change for deprecated calls to io/ioutil using calls to io instead #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand All @@ -17,7 +17,7 @@ import (
"github.com/pkg/errors"
)

//Server holds a HTTP server methods
// Server holds a HTTP server methods
type Server interface {
Start() error
Stop(ctx context.Context) error
Expand Down Expand Up @@ -135,12 +135,12 @@ func (s *server) makeMockEndpoints(endpoints []endpoint) {
}

func (s *server) createEchoHandler(mocks []endpoint, w http.ResponseWriter, r *http.Request) {
reqBody, err := ioutil.ReadAll(r.Body)
reqBody, err := io.ReadAll(r.Body)
if err != nil {
log.Printf("error reading bodyOriginal:%s", err)
return
}
r.Body = ioutil.NopCloser(bytes.NewBuffer(reqBody))
r.Body = io.NopCloser(bytes.NewBuffer(reqBody))

for _, mock := range mocks {
if strings.Contains(string(reqBody), mock.MatchRequest) || mock.MatchRequest == "" {
Expand Down Expand Up @@ -180,10 +180,10 @@ func (s *server) processEchoMock(w http.ResponseWriter, r *http.Request, mock en
item.Header.Set("Content-Type", "application/json")
}

data, _ := ioutil.ReadAll(r.Body)
data, _ := io.ReadAll(r.Body)
item.bodyOriginal = string(data)
item.bodyMock = mock.MockResponse
item.Body = ioutil.NopCloser(bytes.NewBuffer(data))
item.Body = io.NopCloser(bytes.NewBuffer(data))

s.history.AddItem(&item)
item.PrintConsole(w)
Expand Down
4 changes: 2 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"bytes"
"context"
"io/ioutil"
"io"
"log"
"net/http"
"testing"
Expand Down Expand Up @@ -70,7 +70,7 @@ func checkResponseEqual(r *http.Response, sample string) bool {
return false
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
log.Fatalf("error reading bodyOriginal:%+v", err)
}
Expand Down