<commit_before>package udp_output

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"net"
	"os"
	"time"

	"github.com/karimra/gnmic/collector"
	"github.com/karimra/gnmic/outputs"
	"github.com/mitchellh/mapstructure"
	"github.com/prometheus/client_golang/prometheus"
	"google.golang.org/protobuf/proto"
)

func init() {
	outputs.Register("udp", func() outputs.Output {
		return &UDPSock{
			Cfg: &Config{},
		}
	})
}

type UDPSock struct {
	Cfg      *Config
	ctx      context.Context
	cancelFn context.CancelFunc
	buffer   chan []byte
	limiter  *time.Ticker
	logger   *log.Logger
	mo       *collector.MarshalOptions
}

type Config struct {
	Address    string // ip:port
	Rate       time.Duration
	BufferSize uint
	Format     string
}

func (u *UDPSock) Init(cfg map[string]interface{}, logger *log.Logger) error {
	err := mapstructure.Decode(cfg, u.Cfg)
	if err != nil {
		return err
	}
	_, _, err = net.SplitHostPort(u.Cfg.Address)
	if err != nil {
		return fmt.Errorf("wrong address format: %v", err)<commit_msg>add mapstructure struct tags and change decoder<commit_after>package udp_output

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"net"
	"os"
	"time"

	"github.com/karimra/gnmic/collector"
	"github.com/karimra/gnmic/outputs"
	"github.com/mitchellh/mapstructure"
	"github.com/prometheus/client_golang/prometheus"
	"google.golang.org/protobuf/proto"
)

func init() {
	outputs.Register("udp", func() outputs.Output {
		return &UDPSock{
			Cfg: &Config{},
		}
	})
}

type UDPSock struct {
	Cfg      *Config
	ctx      context.Context
	cancelFn context.CancelFunc
	buffer   chan []byte
	limiter  *time.Ticker
	logger   *log.Logger
	mo       *collector.MarshalOptions
}

type Config struct {
	Address    string        `mapstructure:"address,omitempty"` // ip:port
	Rate       time.Duration `mapstructure:"rate,omitempty"`
	BufferSize uint          `mapstructure:"buffer-size,omitempty"`
	Format     string        `mapstructure:"format,omitempty"`
}

func (u *UDPSock) Init(cfg map[string]interface{}, logger *log.Logger) error {
	decoder, err := mapstructure.NewDecoder(
		&mapstructure.DecoderConfig{
			DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
			Result:     u.Cfg,
		},
	)
	if err != nil {
		return err
	}
	err = decoder.Decode(cfg)
	if err != nil {
		return err
	}
	_, _, err = net.SplitHostPort(u.Cfg.Address)
	if err != nil {
		return fmt.Errorf("wrong address format: %v", err)
{'fraction_non_alphanumeric': 0.12976782752902155, 'fraction_numerical': 0.0, 'mean_word_length': 3.6763565891472867, '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': '3288714', 'n_tokens_mistral': 895, 'n_tokens_neox': 853, 'n_words': 183}