Skip to content

Commit

Permalink
refactor: replaced bytes.NewBuffer with bytes.NewBufferString (#473)
Browse files Browse the repository at this point in the history
This PR change one function of bytes package with a similar one, as result code
produce less allocations on heap.
  • Loading branch information
butuzov authored Oct 20, 2021
1 parent 422e2bb commit 00f7ce3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var agentCmd = &cobra.Command{
}

viper.SetConfigType("yaml")
err = viper.ReadConfig(bytes.NewBuffer([]byte(configParsed)))
err = viper.ReadConfig(bytes.NewBufferString(configParsed))

if err != nil {
panic(fmt.Sprintf(
Expand Down
6 changes: 3 additions & 3 deletions core/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h *HTTPClient) Post(ctx context.Context, endpoint string, data string, par
return nil, err
}

req, _ := http.NewRequest("POST", endpoint, bytes.NewBuffer([]byte(data)))
req, _ := http.NewRequest("POST", endpoint, bytes.NewBufferString(data))

req = req.WithContext(ctx)

Expand Down Expand Up @@ -96,7 +96,7 @@ func (h *HTTPClient) Put(ctx context.Context, endpoint string, data string, para
return nil, err
}

req, _ := http.NewRequest("PUT", endpoint, bytes.NewBuffer([]byte(data)))
req, _ := http.NewRequest("PUT", endpoint, bytes.NewBufferString(data))

req = req.WithContext(ctx)

Expand Down Expand Up @@ -126,7 +126,7 @@ func (h *HTTPClient) Patch(ctx context.Context, endpoint string, data string, pa
return nil, err
}

req, _ := http.NewRequest("PATCH", endpoint, bytes.NewBuffer([]byte(data)))
req, _ := http.NewRequest("PATCH", endpoint, bytes.NewBufferString(data))

req = req.WithContext(ctx)

Expand Down
2 changes: 1 addition & 1 deletion pkg/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func LoadConfigs(path string) error {

viper.SetConfigType("yaml")

viper.ReadConfig(bytes.NewBuffer([]byte(data1)))
viper.ReadConfig(bytes.NewBufferString(data1))

viper.SetDefault("app.name", "x-x-x-x")
viper.SetDefault("role", "tower")
Expand Down

0 comments on commit 00f7ce3

Please sign in to comment.