<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"runtime"
	"runtime/debug"
	"strings"
	"time"
)

const (
	PANIC_MAX = 5
	INTERVAL  = 5 //Minute
)

var (
	configuration Settings
	optConf       = flag.String("c", "./config.json", "config file")
	optHelp       = flag.Bool("h", false, "this help")
	panicCount    = 0
)

func identifyPanic() string {
	var name, file string
	var line int
	var pc [16]uintptr

	n := runtime.Callers(3, pc[:])
	for _, pc := range pc[:n] {
		fn := runtime.FuncForPC(pc)
		if fn == nil {
			continue
		}
		file, line = fn.FileLine(pc)
		name = fn.Name()
		if !strings.HasPrefix(name, "runtime.") {
			break
		}
	}

	switch {
	case name != "":
		return fmt.Sprintf("%v:%v", name, line)
	case file != "":
		return fmt.Sprintf("%v:%v", file, line)
	}

	return fmt.Sprintf("pc:%x", pc)
}

func usage() {
	log.Println("[command] -c=[config file path]")
	flag.PrintDefaults()
}

func main() {
	flag.Parse()
	if *optHelp {
		usage()
		return
	}

	var err error
	configuration, err = LoadSettings(*optConf)

	err = InitLogger(configuration.Log_Path, configuration.Log_Size, configuration.Log_Num)
	if err != nil {
		log.Println("InitLogger error:", err)
		return
	}

	if err != nil {
		fmt.Println(err.Error())
		log.Println(err.Error())
		os.Exit(1)
	}

	dnsLoop()
}

func dnsLoop() {
	defer func() {
		if err := recover(); err != nil {
			panicCount++
			log.Printf("Recovered in %v: %v\n", err, debug.Stack())
			fmt.Println(identifyPanic())
			if panicCount < PANIC_MAX {
				log.Println("Got panic in goroutine, will start a new one... :", panicCount)
				go dnsLoop()
			}
		}
	}()

	for {

		domainID := getDomain(configuration.Domain)

		if domainID == -1 {
			continue
		}

		currentIP, err := getCurrentIP(configuration.IP_Url)

		if err != nil {
			log.Println("get_currentIP:", err)
			continue
		}

		subDomainID, ip := getSubDomain(domainID, configuration.Sub_domain)<commit_msg>Add parameter to support dockernize<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"runtime"
	"runtime/debug"
	"strings"
	"time"
)

const (
	PANIC_MAX = 5
	INTERVAL  = 5 //Minute
)

var (
	configuration Settings
	optConf       = flag.String("c", "./config.json", "Specify a config file")
	optDocker     = flag.Bool("d", false, "Run it as docker mode")
	optHelp       = flag.Bool("h", false, "Show help")
	panicCount    = 0
)

func identifyPanic() string {
	var name, file string
	var line int
	var pc [16]uintptr

	n := runtime.Callers(3, pc[:])
	for _, pc := range pc[:n] {
		fn := runtime.FuncForPC(pc)
		if fn == nil {
			continue
		}
		file, line = fn.FileLine(pc)
		name = fn.Name()
		if !strings.HasPrefix(name, "runtime.") {
			break
		}
	}

	switch {
	case name != "":
		return fmt.Sprintf("%v:%v", name, line)
	case file != "":
		return fmt.Sprintf("%v:%v", file, line)
	}

	return fmt.Sprintf("pc:%x", pc)
}

func usage() {
	log.Println("[command] -c=[config file path]")
	flag.PrintDefaults()
}

func main() {
	flag.Parse()
	if *optHelp {
		usage()
		return
	}

	var err error
	configuration, err = LoadSettings(*optConf)

	err = InitLogger(configuration.Log_Path, configuration.Log_Size, configuration.Log_Num)
	if err != nil {
		log.Println("InitLogger error:", err)
		return
	}

	if err != nil {
		fmt.Println(err.Error())
		log.Println(err.Error())
		os.Exit(1)
	}

	dnsLoop()
}

func dnsLoop() {
	defer func() {
		if err := recover(); err != nil {
			panicCount++
			log.Printf("Recovered in %v: %v\n", err, debug.Stack())
			fmt.Println(identifyPanic())
			log.Print(identifyPanic())
			if panicCount < PANIC_MAX {
				log.Println("Got panic in goroutine, will start a new one... :", panicCount)
				go dnsLoop()
			}
		}
	}()

	for {

		domainID := getDomain(configuration.Domain)

		if domainID == -1 {
			continue
		}

		currentIP, err := getCurrentIP(configuration.IP_Url)

		if err != nil {
			log.Println("get_currentIP:", err)
			continue
		}

		subDomainID, ip := getSubDomain(domainID, configuration.Sub_domain)
{'fraction_non_alphanumeric': 0.16089357429718876, 'fraction_numerical': 0.004016064257028112, 'mean_word_length': 3.3268186753528775, 'pattern_counts': {'":': 4, '<': 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': '2901437', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1489, 'n_words': 360}