<commit_before>package data

import (
	"encoding/json"
	"errors"
	"fmt"
	"log"
	"strings"
)

type Builder interface {
	Build(raw []byte) (interface{}, error)
}

type TypeBuilder struct{}

func NewTypeBuilder() Builder {
	return &TypeBuilder{}
}

func (this *TypeBuilder) Build(raw []byte) (interface{}, error) {

	const type_field = "type"

	var data map[string]interface{}
	err := json.Unmarshal(raw, &data)
	if err != nil {
		log.Println("error doing an unmarshal", err.Error())
		return nil, errors.New(fmt.Sprintf("sorry but we do anything with %s", string(raw)))
	}

	if data[type_field] != nil {

		if strings.ToLower(data[type_field].(string)) == "basal" {
			return BuildBasal(data)
		} else if strings.ToLower(data[type_field].(string)) == "deviceevent" {
			return BuildDeviceEvent(data)
		}
		return nil, errors.New(fmt.Sprintf("sorry but we can't deal with `type` %s", data[type_field].(string)))
	}

	return nil, errors.New(fmt.Sprintf("the data had no `type` specified %s", data))

}<commit_msg>keep it const...<commit_after>package data

import (
	"encoding/json"
	"errors"
	"fmt"
	"log"
	"strings"
)

type Builder interface {
	Build(raw []byte) (interface{}, error)
}

type TypeBuilder struct{}

func NewTypeBuilder() Builder {
	return &TypeBuilder{}
}

func (this *TypeBuilder) Build(raw []byte) (interface{}, error) {

	const (
		type_field        = "type"
		basal_type        = "basal"
		device_event_type = "deviceevent"
	)

	var data map[string]interface{}
	err := json.Unmarshal(raw, &data)
	if err != nil {
		log.Println("error doing an unmarshal", err.Error())
		return nil, errors.New(fmt.Sprintf("sorry but we do anything with %s", string(raw)))
	}

	if data[type_field] != nil {

		if strings.ToLower(data[type_field].(string)) == basal_type {
			return BuildBasal(data)
		} else if strings.ToLower(data[type_field].(string)) == device_event_type {
			return BuildDeviceEvent(data)
		}
		return nil, errors.New(fmt.Sprintf("sorry but we can't deal with `type` %s", data[type_field].(string)))
	}

	return nil, errors.New(fmt.Sprintf("the data had no `type` specified %s", data))

}
{'fraction_non_alphanumeric': 0.15512333965844402, 'fraction_numerical': 0.0, 'mean_word_length': 4.564643799472296, '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': '4495696', 'n_tokens_mistral': 767, 'n_tokens_neox': 725, 'n_words': 190}