<commit_before>package main

import (
	"log"
	"path/filepath"
	"strings"

	"github.com/gobwas/glob"
	"gopkg.in/ini.v1"
)

// ConfigUpstream - An upstream config
type ConfigUpstream struct {
	Hostname       string
	Port           int
	TLS            bool
	Timeout        int
	Throttle       int
	WebircPassword string
}

type ConfigServer struct {
	LocalAddr string
	Port      int
	TLS       bool
	CertFile  string
	KeyFile   string
}

// Config - Config options for the running app
var Config struct {
	configFile            string
	logLevel              int
	gateway               bool
	gatewayThrottle       int
	gatewayTimeout        int
	gatewayWebircPassword map[string]string
	upstreams             []ConfigUpstream
	servers               []ConfigServer
	serverEngines         []string
	remoteOrigins         []glob.Glob
	webroot               string
	clientRealname        string
	clientUsername        string
	identd                bool
}

// ConfigResolvePath - If relative, resolve a path to it's full absolute path relative to the config file
func ConfigResolvePath(path string) string {
	// Absolute paths should stay as they are
	if path[0:1] == "/" {
		return path
	}

	resolved := filepath.Dir(Config.configFile)
	resolved = filepath.Clean(resolved + "/" + path)
	return resolved
}

func loadConfig() error {
	cfg, err := ini.LoadSources(ini.LoadOptions{AllowBooleanKeys: true}, Config.configFile)
	if err != nil {
		return err
	}

	// Clear the existing config
	Config.gateway = false
	Config.gatewayWebircPassword = make(map[string]string)
	Config.upstreams = []ConfigUpstream{}
	Config.servers = []ConfigServer{}
	Config.serverEngines = []string{}
	Config.remoteOrigins = []glob.Glob{}
	Config.webroot = ""

	for _, section := range cfg.Sections() {
		if strings.Index(section.Name(), "DEFAULT") == 0 {
			Config.logLevel = section.Key("logLevel").MustInt(3)
			if Config.logLevel < 1 || Config.logLevel > 3 {
				log.Println("Config option logLevel must be between 1-3. Setting default value of 3.")
				Config.logLevel = 3
			}

			Config.identd = section.Key("identd").MustBool(false)
		}

		if section.Name() == "gateway" {
			Config.gateway = section.Key("enabled").MustBool(false)
			Config.gatewayTimeout = section.Key("timeout").MustInt(10)
			Config.gatewayThrottle = section.Key("throttle").MustInt(2)
		}

		if section.Name() == "gateway.webirc" {
			for _, serverAddr := range section.KeyStrings() {
				Config.gatewayWebircPassword[serverAddr] = section.Key(serverAddr).MustString("")
			}
		}

		if strings.Index(section.Name(), "clients") == 0 {
			Config.clientUsername = section.Key("username").MustString("")
			Config.clientRealname = section.Key("realname").MustString("")
		}

		if strings.Index(section.Name(), "fileserving") == 0 {
			if section.Key("enabled").MustBool(false) {
				Config.webroot = section.Key("webroot").MustString("")
			}
		}

		if strings.Index(section.Name(), "server.") == 0 {
			server := ConfigServer{}
			server.LocalAddr = section.Key("bind").MustString("127.0.0.1")
			server.Port = section.Key("port").MustInt(80)
			server.TLS = section.Key("tls").MustBool(false)
			server.CertFile = section.Key("cert").MustString("")
			server.KeyFile = section.Key("key").MustString("")

			Config.servers = append(Config.servers, server)
		}

		if strings.Index(section.Name(), "upstream.") == 0 {
			upstream := ConfigUpstream{}
			upstream.Hostname = section.Key("hostname").MustString("127.0.0.1")
			upstream.Port = section.Key("port").MustInt(6667)
			upstream.TLS = section.Key("tls").MustBool(false)
			upstream.Timeout = section.Key("timeout").MustInt(10)
			upstream.Throttle = section.Key("throttle").MustInt(2)
			upstream.WebircPassword = section.Key("webirc").MustString("")

			Config.upstreams = append(Config.upstreams, upstream)
		}

		if strings.Index(section.Name(), "engines") == 0 {
			for _, engine := range section.KeyStrings() {
				Config.serverEngines = append(Config.serverEngines, strings.Trim(engine, "\n"))
			}
		}

		if strings.Index(section.Name(), "allowed_origins") == 0 {
			for _, origin := range section.KeyStrings() {
				match, err := glob.Compile(glob.QuoteMeta(origin))
				if err != nil {
					log.Println("Config section allowed_origins has invalid match, " + origin)
					continue
				}
				Config.remoteOrigins = append(Config.remoteOrigins, match)
			}
		}
	}

	return nil
}
<commit_msg>Don’t quote the origin match patterns<commit_after>package main

import (
	"log"
	"path/filepath"
	"strings"

	"github.com/gobwas/glob"
	"gopkg.in/ini.v1"
)

// ConfigUpstream - An upstream config
type ConfigUpstream struct {
	Hostname       string
	Port           int
	TLS            bool
	Timeout        int
	Throttle       int
	WebircPassword string
}

type ConfigServer struct {
	LocalAddr string
	Port      int
	TLS       bool
	CertFile  string
	KeyFile   string
}

// Config - Config options for the running app
var Config struct {
	configFile            string
	logLevel              int
	gateway               bool
	gatewayThrottle       int
	gatewayTimeout        int
	gatewayWebircPassword map[string]string
	upstreams             []ConfigUpstream
	servers               []ConfigServer
	serverEngines         []string
	remoteOrigins         []glob.Glob
	webroot               string
	clientRealname        string
	clientUsername        string
	identd                bool
}

// ConfigResolvePath - If relative, resolve a path to it's full absolute path relative to the config file
func ConfigResolvePath(path string) string {
	// Absolute paths should stay as they are
	if path[0:1] == "/" {
		return path
	}

	resolved := filepath.Dir(Config.configFile)
	resolved = filepath.Clean(resolved + "/" + path)
	return resolved
}

func loadConfig() error {
	cfg, err := ini.LoadSources(ini.LoadOptions{AllowBooleanKeys: true}, Config.configFile)
	if err != nil {
		return err
	}

	// Clear the existing config
	Config.gateway = false
	Config.gatewayWebircPassword = make(map[string]string)
	Config.upstreams = []ConfigUpstream{}
	Config.servers = []ConfigServer{}
	Config.serverEngines = []string{}
	Config.remoteOrigins = []glob.Glob{}
	Config.webroot = ""

	for _, section := range cfg.Sections() {
		if strings.Index(section.Name(), "DEFAULT") == 0 {
			Config.logLevel = section.Key("logLevel").MustInt(3)
			if Config.logLevel < 1 || Config.logLevel > 3 {
				log.Println("Config option logLevel must be between 1-3. Setting default value of 3.")
				Config.logLevel = 3
			}

			Config.identd = section.Key("identd").MustBool(false)
		}

		if section.Name() == "gateway" {
			Config.gateway = section.Key("enabled").MustBool(false)
			Config.gatewayTimeout = section.Key("timeout").MustInt(10)
			Config.gatewayThrottle = section.Key("throttle").MustInt(2)
		}

		if section.Name() == "gateway.webirc" {
			for _, serverAddr := range section.KeyStrings() {
				Config.gatewayWebircPassword[serverAddr] = section.Key(serverAddr).MustString("")
			}
		}

		if strings.Index(section.Name(), "clients") == 0 {
			Config.clientUsername = section.Key("username").MustString("")
			Config.clientRealname = section.Key("realname").MustString("")
		}

		if strings.Index(section.Name(), "fileserving") == 0 {
			if section.Key("enabled").MustBool(false) {
				Config.webroot = section.Key("webroot").MustString("")
			}
		}

		if strings.Index(section.Name(), "server.") == 0 {
			server := ConfigServer{}
			server.LocalAddr = section.Key("bind").MustString("127.0.0.1")
			server.Port = section.Key("port").MustInt(80)
			server.TLS = section.Key("tls").MustBool(false)
			server.CertFile = section.Key("cert").MustString("")
			server.KeyFile = section.Key("key").MustString("")

			Config.servers = append(Config.servers, server)
		}

		if strings.Index(section.Name(), "upstream.") == 0 {
			upstream := ConfigUpstream{}
			upstream.Hostname = section.Key("hostname").MustString("127.0.0.1")
			upstream.Port = section.Key("port").MustInt(6667)
			upstream.TLS = section.Key("tls").MustBool(false)
			upstream.Timeout = section.Key("timeout").MustInt(10)
			upstream.Throttle = section.Key("throttle").MustInt(2)
			upstream.WebircPassword = section.Key("webirc").MustString("")

			Config.upstreams = append(Config.upstreams, upstream)
		}

		if strings.Index(section.Name(), "engines") == 0 {
			for _, engine := range section.KeyStrings() {
				Config.serverEngines = append(Config.serverEngines, strings.Trim(engine, "\n"))
			}
		}

		if strings.Index(section.Name(), "allowed_origins") == 0 {
			for _, origin := range section.KeyStrings() {
				match, err := glob.Compile(origin)
				if err != nil {
					log.Println("Config section allowed_origins has invalid match, " + origin)
					continue
				}
				Config.remoteOrigins = append(Config.remoteOrigins, match)
			}
		}
	}

	return nil
}

{'fraction_non_alphanumeric': 0.13506139154160982, 'fraction_numerical': 0.009322419281491587, 'mean_word_length': 3.3614278631631134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4388469', 'n_tokens_mistral': 3098, 'n_tokens_neox': 2774, 'n_words': 585}