<commit_before>//
// Copyright (c) 2017
// Cavium
//
// SPDX-License-Identifier: Apache-2.0
//

package distro

import (
	"encoding/json"
	"net/http"
	"strconv"

	"github.com/drasko/edgex-export"
	"go.uber.org/zap"
)

const (
	// TODO this consts need to be configurable somehow
	clientHost     = "127.0.0.1"
	clientPort int = 48071
)

func getRegistrations() []export.Registration {
	url := "http://" + clientHost + ":" + strconv.Itoa(clientPort) +
		"/api/v1/registration"

	response, err := http.Get(url)
	if err != nil {
		logger.Error("Error getting all registrations", zap.String("url", url))
		return nil
	}
	defer response.Body.Close()

	results := []export.Registration{}
	if err := json.NewDecoder(response.Body).Decode(&results); err != nil {
		logger.Error("Could not parse json", zap.Error(err))
	}

	return results
}

func getRegistrationByName(name string) *export.Registration {
	url := "http://" + clientHost + ":" + strconv.Itoa(clientPort) +
		"/api/v1/registration/name/" + name

	response, err := http.Get(url)
	if err != nil {
		logger.Error("Error getting all registrations", zap.String("url", url))
		return nil
	}
	defer response.Body.Close()

	reg := export.Registration{}
	if err := json.NewDecoder(response.Body).Decode(&reg); err != nil {
		logger.Error("Could not parse json", zap.Error(err))
	}

	return &reg
}<commit_msg>Do not log as errors<commit_after>//
// Copyright (c) 2017
// Cavium
//
// SPDX-License-Identifier: Apache-2.0
//

package distro

import (
	"encoding/json"
	"net/http"
	"strconv"

	"github.com/drasko/edgex-export"
	"go.uber.org/zap"
)

const (
	// TODO this consts need to be configurable somehow
	clientHost     = "127.0.0.1"
	clientPort int = 48071
)

func getRegistrations() []export.Registration {
	url := "http://" + clientHost + ":" + strconv.Itoa(clientPort) +
		"/api/v1/registration"

	response, err := http.Get(url)
	if err != nil {
		logger.Warn("Error getting all registrations", zap.String("url", url))
		return nil
	}
	defer response.Body.Close()

	results := []export.Registration{}
	if err := json.NewDecoder(response.Body).Decode(&results); err != nil {
		logger.Warn("Could not parse json", zap.Error(err))
	}

	return results
}

func getRegistrationByName(name string) *export.Registration {
	url := "http://" + clientHost + ":" + strconv.Itoa(clientPort) +
		"/api/v1/registration/name/" + name

	response, err := http.Get(url)
	if err != nil {
		logger.Error("Error getting all registrations", zap.String("url", url))
		return nil
	}
	defer response.Body.Close()

	reg := export.Registration{}
	if err := json.NewDecoder(response.Body).Decode(&reg); err != nil {
		logger.Error("Could not parse json", zap.Error(err))
	}

	return &reg
}
{'fraction_non_alphanumeric': 0.16746587974917004, 'fraction_numerical': 0.014016967908520842, 'mean_word_length': 3.8170515097690942, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '757367', 'n_tokens_mistral': 997, 'n_tokens_neox': 949, 'n_words': 218}