<commit_before>package main

import (
	"encoding/json"
	"net/http"
	"runtime"
	"strconv"

	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"math/rand"
)

const DB_ROWS = 10000

var db *sql.DB
var q *sql.Stmt

type MessageStruct struct {
	Message string
}
type World struct {
	Id           uint16 `json:"id"`
	RandomNumber uint16 `json:"randomNumber"`
}

func hello(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/javascript")
	j, _ := json.Marshal(&MessageStruct{"Hello, world"})
	w.Header().Set("Content-Length", strconv.Itoa(len(j)))
	w.Write(j)
}

func dbh(w http.ResponseWriter, r *http.Request) {
	qnum := 1
	qnumString := r.URL.Query().Get("queries")
	if len(qnumString) != 0 {
		qnum, _ = strconv.Atoi(qnumString)
	}
	ww := make([]World, qnum)
	for i := 0; i < qnum; i++ {
		q.QueryRow(rand.Intn(DB_ROWS)+1).Scan(&ww[i].Id, &ww[i].RandomNumber)
	}
	w.Header().Set("Content-Type", "application/javascript")
	j, _ := json.Marshal(ww)
	w.Header().Set("Content-Length", strconv.Itoa(len(j)))
	w.Write(j)
}

func main() {
	var err error
	runtime.GOMAXPROCS(runtime.NumCPU())

	db, err = sql.Open("mysql", "benchmarkdbuser:benchmarkdbpass@tcp(localhost:3306)/hello_world?charset=utf8")
	if err != nil {
		log.Fatalf("Error opening database: %s", err)
	}
	q, err = db.Prepare("SELECT * FROM World where id = ?;")
	if err != nil {
		log.Fatalf("Error preparing statement: %s", err)
	}

	http.HandleFunc("/json", hello)
	http.HandleFunc("/db", dbh)
	http.ListenAndServe(":8080", nil)
}<commit_msg>Go: Cleanup source code.<commit_after>package main

import (
	"database/sql"
	"encoding/json"
	_ "github.com/go-sql-driver/mysql"
	"log"
	"math/rand"
	"net/http"
	"runtime"
	"strconv"
)

type MessageStruct struct {
	Message string
}

type World struct {
	Id           uint16 `json:"id"`
	RandomNumber uint16 `json:"randomNumber"`
}

const (
	DB_CONN_STR   = "benchmarkdbuser:benchmarkdbpass@tcp(localhost:3306)/hello_world?charset=utf8"
	DB_SELECT_SQL = "SELECT * FROM World where id = ?;"
	DB_ROWS       = 10000
)

var (
	db    *sql.DB
	query *sql.Stmt
)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	var err error
	if db, err = sql.Open("mysql", DB_CONN_STR); err != nil {
		log.Fatalf("Error opening database: %s", err)
	}
	if query, err = db.Prepare(DB_SELECT_SQL); err != nil {
		log.Fatalf("Error preparing statement: %s", err)
	}
	http.HandleFunc("/json", jsonHandler)
	http.HandleFunc("/db", dbHandler)
	http.ListenAndServe(":8080", nil)
}

func jsonHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/javascript")
	j, _ := json.Marshal(&MessageStruct{"Hello, world"})
	w.Header().Set("Content-Length", strconv.Itoa(len(j)))
	w.Write(j)
}

func dbHandler(w http.ResponseWriter, r *http.Request) {
	qnum := 1
	if qnumStr := r.URL.Query().Get("queries"); len(qnumStr) != 0 {
		qnum, _ = strconv.Atoi(qnumStr)
	}
	ww := make([]World, qnum)
	for i := 0; i < qnum; i++ {
		query.QueryRow(rand.Intn(DB_ROWS)+1).Scan(&ww[i].Id, &ww[i].RandomNumber)
	}
	w.Header().Set("Content-Type", "application/javascript")
	j, _ := json.Marshal(ww)
	w.Header().Set("Content-Length", strconv.Itoa(len(j)))
	w.Write(j)
}
{'fraction_non_alphanumeric': 0.18332292317301688, 'fraction_numerical': 0.013741411617738912, 'mean_word_length': 4.493996569468267, 'pattern_counts': {'":': 2, '<': 5, '<?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': '5409430', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1258, 'n_words': 242}