<commit_before>package model

import (
	"bytes"
	"fmt"
	"go/format"
	"io"
	"os"
	"text/template"
)

// Generate writes a Go file with a client for using the parsed service.
func Generate(w io.Writer) error {
	t := template.New("root").Funcs(template.FuncMap{
		"godoc":      godoc,
		"exportable": exportable,
	})
	template.Must(common(t))
	template.Must(jsonClient(t))
	template.Must(queryClient(t))
	template.Must(ec2Client(t))
	template.Must(restCommon(t))
	template.Must(restXMLClient(t))
	template.Must(restJSONClient(t))

	out := bytes.NewBuffer(nil)
	if err := t.ExecuteTemplate(out, service.Metadata.Protocol, service); err != nil {
		return err
	}

	b, err := format.Source(out.Bytes())
	if err != nil {
		fmt.Fprint(os.Stdout, out.String())
		return err
	}

	_, err = io.Copy(w, bytes.NewReader(b))
	return err
}

func common(t *template.Template) (*template.Template, error) {
	return t.Parse(`<commit_msg>Simplify buffer handling.<commit_after>package model

import (
	"bytes"
	"fmt"
	"go/format"
	"io"
	"os"
	"text/template"
)

// Generate writes a Go file with a client for using the parsed service.
func Generate(w io.Writer) error {
	t := template.New("root").Funcs(template.FuncMap{
		"godoc":      godoc,
		"exportable": exportable,
	})
	template.Must(common(t))
	template.Must(jsonClient(t))
	template.Must(queryClient(t))
	template.Must(ec2Client(t))
	template.Must(restCommon(t))
	template.Must(restXMLClient(t))
	template.Must(restJSONClient(t))

	out := new(bytes.Buffer)
	if err := t.ExecuteTemplate(out, service.Metadata.Protocol, service); err != nil {
		return err
	}

	b, err := format.Source(out.Bytes())
	if err != nil {
		fmt.Fprint(os.Stdout, out.String())
		return err
	}

	_, err = w.Write(b)
	return err
}

func common(t *template.Template) (*template.Template, error) {
	return t.Parse(`
{'fraction_non_alphanumeric': 0.15743280307185958, 'fraction_numerical': 0.0010970927043335162, 'mean_word_length': 4.493975903614458, 'pattern_counts': {'":': 4, '<': 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': '6373139', 'n_tokens_mistral': 679, 'n_tokens_neox': 660, 'n_words': 144}