<commit_before>package main

import (
	"bufio"
	"crypto/tls"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"os/signal"
	"sync"
	"syscall"
	"time"

	ini "gopkg.in/ini.v1"

	"github.com/mengzhuo/bla"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
	DefaultConfig = "config.ini"
)

var (
	configPath = flag.String("config", DefaultConfig, "default config path")
	version    = flag.Bool("version", false, "show version")

	logPool = sync.Pool{New: func() interface{} { return &LogWriter{nil, 200} }}
	tlsCert *tls.Certificate
	server  *http.Server
	Version string = "dev"
)

func main() {
	//defer profile.Start().Stop()
	flag.Parse()

	if *version {
		fmt.Println("bla version:", Version)
		return
	}

	raw, err := ini.Load(*configPath)
	if err != nil {
		log.Fatal(err)
	}

	raw.MapTo(cfg)

	log.Printf("pid:%d", os.Getpid())

	if cfg.MetricListen != "" {
		go loadMetric(cfg.MetricListen)
	}

	log.Printf("Server:%v", cfg)

	h := bla.NewHandler(*configPath)

	lh := logTimeAndStatus(h)
	server = &http.Server{Addr: cfg.Listen, Handler: lh}

	if cfg.Certfile != "" && cfg.Keyfile != "" {
		// for higher score in ssllab
		server.TLSConfig = &tls.Config{
			MinVersion:               tls.VersionTLS12,
			CurvePreferences:         []tls.CurveID{tls.CurveP384, tls.CurveP256, tls.CurveP521},
			PreferServerCipherSuites: true,
		}
		server.TLSConfig.GetCertificate = getCertificate
		log.Printf("TLS:%s, %s", cfg.Certfile, cfg.Keyfile)
		watchReloadCert()
		log.Fatal(server.ListenAndServeTLS(cfg.Certfile, cfg.Keyfile))
	}
	server.ListenAndServe()

}

func logTimeAndStatus(handler http.Handler) http.Handler {

	var (
		writer io.Writer
		err    error
	)

	if cfg.AccessLogPath != "" {
		var file *os.File<commit_msg>for performance change curve back to 256<commit_after>package main

import (
	"bufio"
	"crypto/tls"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"os/signal"
	"sync"
	"syscall"
	"time"

	ini "gopkg.in/ini.v1"

	"github.com/mengzhuo/bla"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
	DefaultConfig = "config.ini"
)

var (
	configPath = flag.String("config", DefaultConfig, "default config path")
	version    = flag.Bool("version", false, "show version")

	logPool = sync.Pool{New: func() interface{} { return &LogWriter{nil, 200} }}
	tlsCert *tls.Certificate
	server  *http.Server
	Version string = "dev"
)

func main() {
	// defer profile.Start().Stop()
	flag.Parse()

	if *version {
		fmt.Println("bla version:", Version)
		return
	}

	raw, err := ini.Load(*configPath)
	if err != nil {
		log.Fatal(err)
	}

	raw.MapTo(cfg)

	log.Printf("pid:%d", os.Getpid())

	if cfg.MetricListen != "" {
		go loadMetric(cfg.MetricListen)
	}

	log.Printf("Server:%v", cfg)

	h := bla.NewHandler(*configPath)

	lh := logTimeAndStatus(h)
	server = &http.Server{Addr: cfg.Listen, Handler: lh}

	if cfg.Certfile != "" && cfg.Keyfile != "" {
		// for higher score in ssllab
		server.TLSConfig = &tls.Config{
			MinVersion:               tls.VersionTLS12,
			PreferServerCipherSuites: true,
		}
		server.TLSConfig.GetCertificate = getCertificate
		log.Printf("TLS:%s, %s", cfg.Certfile, cfg.Keyfile)
		watchReloadCert()
		log.Fatal(server.ListenAndServeTLS(cfg.Certfile, cfg.Keyfile))
	}
	server.ListenAndServe()

}

func logTimeAndStatus(handler http.Handler) http.Handler {

	var (
		writer io.Writer
		err    error
	)

	if cfg.AccessLogPath != "" {
		var file *os.File
{'fraction_non_alphanumeric': 0.15590327169274537, 'fraction_numerical': 0.0068278805120910386, 'mean_word_length': 3.8496551724137933, 'pattern_counts': {'":': 0, '<': 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': '4774583', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1333, 'n_words': 255}