<commit_before>package resource

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"os"
	"strconv"
	"time"
)

// Provides access to resources through a http.Client.
type HTTPProvider struct {
	Client *http.Client
}

var _ Provider = &HTTPProvider{}

func (me *HTTPProvider) NewInstance(urlStr string) (r Instance, err error) {
	_r := new(httpInstance)
	_r.URL, err = url.Parse(urlStr)
	if err != nil {
		return
	}
	_r.Client = me.Client
	if _r.Client == nil {
		_r.Client = http.DefaultClient
	}
	r = _r
	return
}

type httpInstance struct {
	Client *http.Client
	URL    *url.URL
}

var _ Instance = &httpInstance{}

func mustNewRequest(method, urlStr string, body io.Reader) *http.Request {
	req, err := http.NewRequest(method, urlStr, body)
	if err != nil {
		panic(err)
	}
	return req
}

func responseError(r *http.Response) error {
	if r.StatusCode == http.StatusNotFound {
		return os.ErrNotExist
	}
	return errors.New(r.Status)
}

func (me *httpInstance) Get() (ret io.ReadCloser, err error) {
	resp, err := me.Client.Get(me.URL.String())
	if err != nil {
		return
	}
	if resp.StatusCode == http.StatusOK {
		ret = resp.Body
		return
	}
	resp.Body.Close()
	err = errors.New(resp.Status)
	return
}

func (me *httpInstance) Put(r io.Reader) (err error) {
	resp, err := me.Client.Do(mustNewRequest("PUT", me.URL.String(), r))
	if err != nil {
		return
	}<commit_msg>resource.httpInstance.Get: Use responseError for handling errors<commit_after>package resource

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"os"
	"strconv"
	"time"
)

// Provides access to resources through a http.Client.
type HTTPProvider struct {
	Client *http.Client
}

var _ Provider = &HTTPProvider{}

func (me *HTTPProvider) NewInstance(urlStr string) (r Instance, err error) {
	_r := new(httpInstance)
	_r.URL, err = url.Parse(urlStr)
	if err != nil {
		return
	}
	_r.Client = me.Client
	if _r.Client == nil {
		_r.Client = http.DefaultClient
	}
	r = _r
	return
}

type httpInstance struct {
	Client *http.Client
	URL    *url.URL
}

var _ Instance = &httpInstance{}

func mustNewRequest(method, urlStr string, body io.Reader) *http.Request {
	req, err := http.NewRequest(method, urlStr, body)
	if err != nil {
		panic(err)
	}
	return req
}

func responseError(r *http.Response) error {
	if r.StatusCode == http.StatusNotFound {
		return os.ErrNotExist
	}
	return errors.New(r.Status)
}

func (me *httpInstance) Get() (ret io.ReadCloser, err error) {
	resp, err := me.Client.Get(me.URL.String())
	if err != nil {
		return
	}
	if resp.StatusCode == http.StatusOK {
		ret = resp.Body
		return
	}
	resp.Body.Close()
	err = responseError(resp)
	return
}

func (me *httpInstance) Put(r io.Reader) (err error) {
	resp, err := me.Client.Do(mustNewRequest("PUT", me.URL.String(), r))
	if err != nil {
		return
	}
{'fraction_non_alphanumeric': 0.13960923623445826, 'fraction_numerical': 0.0, 'mean_word_length': 3.7248322147651005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1019606', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1066, 'n_words': 275}