<commit_before>package couchdb2_goclient

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"time"
)

var doDebug bool = false

type CouchDb2ConnDetails struct {
	Client   *http.Client
	Address  string
	Username string
	Password string
	protocol string
}

func (s *CouchDb2ConnDetails) bytesRequester(method, url string, reqBody io.Reader) (byt []byte, err error) {
	if s.Client == nil {
		return nil, errors.New("You must set an HTTP Client to make requests. Current client is nil")
	}

	if doDebug {
		fmt.Printf("%s://%s%s\n", s.protocol, s.Address, url)
	}
	req, err := http.NewRequest(method, fmt.Sprintf("%s://%s%s", s.protocol, s.Address, url), reqBody)
	if err != nil {
		return nil, err
	}

	if s.Username != "" && s.Password != "" {
		req.SetBasicAuth(s.Username, s.Password)
	}

	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")

	httpRes, err := s.Client.Do(req)
	if err != nil {
		return nil, err
	}

	defer httpRes.Body.Close()
	byt, err = ioutil.ReadAll(httpRes.Body)
	return byt, err
}

func (s *CouchDb2ConnDetails) requester(method, url string, reqBody io.Reader, res interface{}) error {
	if s.Client == nil {
		return errors.New("You must set an HTTP Client to make requests. Current client is nil")
	}

	if doDebug {
		fmt.Printf("%s://%s%s\n", s.protocol, s.Address, url)
	}
	req, err := http.NewRequest(method, fmt.Sprintf("%s://%s%s", s.protocol, s.Address, url), reqBody)
	if err != nil {
		return err
	}

	if s.Username != "" && s.Password != "" {
		req.SetBasicAuth(s.Username, s.Password)
	}

	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")

	httpRes, err := s.Client.Do(req)
	if err != nil {
		return err
	}

	if doDebug {
		var byt []byte
		byt, err = ioutil.ReadAll(httpRes.Body)
		defer httpRes.Body.Close()
		if err != nil {
			return err
		}

		//fmt.Printf("a %#v\n", string(byt))

		json.Unmarshal(byt, &res)
		if err != nil {
			return fmt.Errorf("Error parsing response: %s", err.Error())
		}
		fmt.Printf("c %#v\n", res)

	} else {

		err = json.NewDecoder(httpRes.Body).Decode(&res)
		if err != nil {
			return fmt.Errorf("Error parsing response: %s", err.Error())
		}
	}

	return nil
}

func NewConnection(t time.Duration, addr string, user, pass string, secure bool) (conn *CouchDb2ConnDetails) {
	conn = &CouchDb2ConnDetails{
		Client: &http.Client{
			Timeout: t,
		},
		Address:  addr,
		Username: user,
		Password: <PASSWORD>,
		protocol: "http",
	}

	if secure {
		conn.Client.Transport = &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		conn.protocol = "https"
	}

	return conn
}<commit_msg>Improve naming of timeout arg<commit_after>package couchdb2_goclient

import (
	"crypto/tls"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"time"
)

var doDebug bool = false

type CouchDb2ConnDetails struct {
	Client   *http.Client
	Address  string
	Username string
	Password string
	protocol string
}

func (s *CouchDb2ConnDetails) bytesRequester(method, url string, reqBody io.Reader) (byt []byte, err error) {
	if s.Client == nil {
		return nil, errors.New("You must set an HTTP Client to make requests. Current client is nil")
	}

	if doDebug {
		fmt.Printf("%s://%s%s\n", s.protocol, s.Address, url)
	}
	req, err := http.NewRequest(method, fmt.Sprintf("%s://%s%s", s.protocol, s.Address, url), reqBody)
	if err != nil {
		return nil, err
	}

	if s.Username != "" && s.Password != "" {
		req.SetBasicAuth(s.Username, s.Password)
	}

	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")

	httpRes, err := s.Client.Do(req)
	if err != nil {
		return nil, err
	}

	defer httpRes.Body.Close()
	byt, err = ioutil.ReadAll(httpRes.Body)
	return byt, err
}

func (s *CouchDb2ConnDetails) requester(method, url string, reqBody io.Reader, res interface{}) error {
	if s.Client == nil {
		return errors.New("You must set an HTTP Client to make requests. Current client is nil")
	}

	if doDebug {
		fmt.Printf("%s://%s%s\n", s.protocol, s.Address, url)
	}
	req, err := http.NewRequest(method, fmt.Sprintf("%s://%s%s", s.protocol, s.Address, url), reqBody)
	if err != nil {
		return err
	}

	if s.Username != "" && s.Password != "" {
		req.SetBasicAuth(s.Username, s.Password)
	}

	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")

	httpRes, err := s.Client.Do(req)
	if err != nil {
		return err
	}

	if doDebug {
		var byt []byte
		byt, err = ioutil.ReadAll(httpRes.Body)
		defer httpRes.Body.Close()
		if err != nil {
			return err
		}

		//fmt.Printf("a %#v\n", string(byt))

		json.Unmarshal(byt, &res)
		if err != nil {
			return fmt.Errorf("Error parsing response: %s", err.Error())
		}
		fmt.Printf("c %#v\n", res)

	} else {

		err = json.NewDecoder(httpRes.Body).Decode(&res)
		if err != nil {
			return fmt.Errorf("Error parsing response: %s", err.Error())
		}
	}

	return nil
}

func NewConnection(timeout time.Duration, addr string, user, pass string, secure bool) (conn *CouchDb2ConnDetails) {
	conn = &CouchDb2ConnDetails{
		Client: &http.Client{
			Timeout: timeout,
		},
		Address:  addr,
		Username: user,
		Password: <PASSWORD>,
		protocol: "http",
	}

	if secure {
		conn.Client.Transport = &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		conn.protocol = "https"
	}

	return conn
}
{'fraction_non_alphanumeric': 0.15938303341902313, 'fraction_numerical': 0.0022034520749173708, 'mean_word_length': 3.6916451335055984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6209481', 'n_tokens_mistral': 2136, 'n_tokens_neox': 2018, 'n_words': 506}