<commit_before><commit_msg>config: package, exporting variables<commit_after>package config

import (
	"fmt"
	"os"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/rvolosatovs/systemgo/system"
	"github.com/spf13/viper"
)

const (
	DEFAULT_PORT   = 8000
	DEFAULT_TARGET = "default.target"
	RESCUE_TARGET  = "rescue.target"
)

var (
	// Default target
	Target string

	// Paths to search for unit files
	Paths []string

	// Port for system daemon to listen on
	Port port

	// Retry specifies the period(in seconds) to wait before
	// restarting the http service if it fails
	Retry time.Duration

	// Wheter to show debugging statements
	Debug bool
)

type port int

func (p port) String() string {
	return fmt.Sprintf(":%v", int(p))
}

func init() {
	viper.SetDefault("port", DEFAULT_PORT)
	viper.SetDefault("target", DEFAULT_TARGET)
	viper.SetDefault("paths", system.DEFAULT_PATHS)
	viper.SetDefault("retry", 1)
	viper.SetDefault("debug", false)

	viper.SetEnvPrefix("systemgo")
	viper.AutomaticEnv()

	viper.SetConfigName("systemgo")

	viper.AddConfigPath(".")
	if os.Getenv("XDG_CONFIG_HOME") != "" {
		viper.AddConfigPath("$XDG_CONFIG_HOME/systemgo")
	}
	viper.AddConfigPath("/etc/systemgo")

	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Error reading %s: %s", viper.ConfigFileUsed(), err)
	}
	log.Infof("Found configuration file at %s", viper.ConfigFileUsed())

	Target = viper.GetString("target")
	Paths = viper.GetStringSlice("paths")
	Port = port(viper.GetInt("port"))
	Retry = viper.GetDuration("retry")
	Debug = viper.GetBool("debug")

	if Debug {
		log.SetLevel(log.DebugLevel)
	}
}
{'fraction_non_alphanumeric': 0.14135151890886546, 'fraction_numerical': 0.0043397396156230625, 'mean_word_length': 4.663157894736842, 'pattern_counts': {'":': 1, '<': 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': '605979', 'n_tokens_mistral': 598, 'n_tokens_neox': 581, 'n_words': 127}