<commit_before>package config

import (
	"fmt"
	"os"
	"path/filepath"

	mylog "github.com/patrickalin/GoMyLog"
	viper "github.com/spf13/viper"
)

const bloomskyURL = "bloomsky_url"
const bloomskyAccessToken = "bloomsky_access_token"
const influxDBDatabase = "influxDB_database"
const influxDBPassword = "<PASSWORD>"
const influxDBServer = "influxDB_server"
const influxDBServerPort = "influxDB_server_port"
const influxDBUsername = "influxDB_username"
const consoleActivated = "console_activated"
const influxDBActivated = "influxDB_activated"
const refreshTimer = "refresh_timer"
const logLevel = "log_level"

//ConfigStructure is the structure of the config YAML file
//use http://mervine.net/json2struct
type ConfigStructure struct {
	ConsoleActivated    string `json:"console_activated"`
	InfluxDBActivated   string `json:"influxDB_activated"`
	InfluxDBDatabase    string `json:"influxDB_database"`
	InfluxDBPassword    string `json:"<PASSWORD>"`
	InfluxDBServer      string `json:"influxDB_server"`
	InfluxDBServerPort  string `json:"influxDB_server_port"`
	InfluxDBUsername    string `json:"influxDB_username"`
	LogLevel            string `json:"log_level"`
	BloomskyAccessToken string `json:"bloomsky_access_token"`
	BloomskyURL         string `json:"bloomsky_url"`
	RefreshTimer        string `json:"refresh_timer"`
}

//Config GetURL return the URL from the config file
type Config interface {
	GetURL() string
}

// ReadConfig read config from config.json
// with the package viper
func (configInfo ConfigStructure) ReadConfig(configName string) ConfigStructure {
	viper.SetConfigName(configName)
	viper.AddConfigPath(".")
	viper.AddConfigPath("./config/")

	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		mylog.Error.Fatal(err)
	}

	mylog.Trace.Printf("The config file loaded is :> %s/%s \n \n", dir, configName)

	dir = dir + "/" + configName

	err = viper.ReadInConfig()
	if err != nil {
		fmt.Printf("File not found:> %s/%s \n \n", dir, configName)
		mylog.Error.Fatal(err)
	}

	configInfo.BloomskyURL = viper.GetString(bloomskyURL)<commit_msg>Improve err<commit_after>package config

import (
	"fmt"
	"os"
	"path/filepath"

	mylog "github.com/patrickalin/GoMyLog"
	viper "github.com/spf13/viper"
)

const bloomskyURL = "bloomsky_url"
const bloomskyAccessToken = "bloomsky_access_token"
const influxDBDatabase = "influxDB_database"
const influxDBPassword = "<PASSWORD>"
const influxDBServer = "influxDB_server"
const influxDBServerPort = "influxDB_server_port"
const influxDBUsername = "influxDB_username"
const consoleActivated = "console_activated"
const influxDBActivated = "influxDB_activated"
const refreshTimer = "refresh_timer"
const logLevel = "log_level"

//ConfigStructure is the structure of the config YAML file
//use http://mervine.net/json2struct
type ConfigStructure struct {
	ConsoleActivated    string `json:"console_activated"`
	InfluxDBActivated   string `json:"influxDB_activated"`
	InfluxDBDatabase    string `json:"influxDB_database"`
	InfluxDBPassword    string `json:"influxDB_password"`
	InfluxDBServer      string `json:"influxDB_server"`
	InfluxDBServerPort  string `json:"influxDB_server_port"`
	InfluxDBUsername    string `json:"influxDB_username"`
	LogLevel            string `json:"log_level"`
	BloomskyAccessToken string `json:"bloomsky_access_token"`
	BloomskyURL         string `json:"bloomsky_url"`
	RefreshTimer        string `json:"refresh_timer"`
}

//Config GetURL return the URL from the config file
type Config interface {
	GetURL() string
}

// ReadConfig read config from config.json
// with the package viper
func (configInfo ConfigStructure) ReadConfig(configName string) ConfigStructure {
	viper.SetConfigName(configName)
	viper.AddConfigPath(".")
	viper.AddConfigPath("./config/")

	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))

	if err != nil {
		mylog.Error.Fatal(err)
	}

	mylog.Trace.Printf("The config file loaded is :> %s/%s \n \n", dir, configName)

	dir = dir + "/" + configName

	if err := viper.ReadInConfig(); err != nil {
		fmt.Printf("File not found:> %s/%s \n \n", dir, configName)
		mylog.Error.Fatal(err)
	}

	configInfo.BloomskyURL = viper.GetString(bloomskyURL)
{'fraction_non_alphanumeric': 0.11033821060206285, 'fraction_numerical': 0.001918925401775006, 'mean_word_length': 5.261261261261262, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '6112765', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1404, 'n_words': 316}