<commit_before><commit_msg>First draft of the idea<commit_after>package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	_ "github.com/lib/pq"
	"log"
	"net"
	"net/http"
	"strconv"
)

var (
	database struct {
		kind     string // mysql or postgres
		name     string
		username string
		password string
		host     string
	}

	domainTable string

	acl []net.IP
)

func main() {
	db, err := connectDatabase()
	if err != nil {
		log.Fatal(err)
	}

	http.Handle("/domains/registered", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		remoteAddr := net.ParseIP(r.RemoteAddr)
		if remoteAddr == nil {
			w.WriteHeader(http.StatusUnauthorized)
			return
		}

		var grant bool
		for _, ip := range acl {
			if remoteAddr.Equal(ip) {
				grant = true
				break
			}
		}

		if !grant {
			w.WriteHeader(http.StatusUnauthorized)
			return
		}

		query := fmt.Sprintf("SELECT COUNT(*) FROM %s", domainTable)

		row := db.QueryRow(query)

		var registeredDomains int
		if err := row.Scan(&registeredDomains); err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		w.Write([]byte(strconv.Itoa(registeredDomains)))
	}))

	log.Fatal(http.ListenAndServe(":8888", nil))
}

func connectDatabase() (*sql.DB, error) {
	var connParams string
	switch database.kind {
	case "mysql":
		connParams = fmt.Sprintf("%s:%s@tcp(%s)/%s",
			database.username,
			database.password,
			database.host,
			database.name,
		)
	case "postgres":
		connParams = fmt.Sprintf("postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full",
			database.username,
			database.password,
			database.host,
			database.name,
		)
	}

	return sql.Open(database.kind, connParams)
}

{'fraction_non_alphanumeric': 0.13681159420289854, 'fraction_numerical': 0.002318840579710145, 'mean_word_length': 3.5301837270341205, 'pattern_counts': {'":': 3, '<': 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': '7434417', 'n_tokens_mistral': 695, 'n_tokens_neox': 605, 'n_words': 122}