package main import ( "github.com/jackc/pgx/pgxpool" "github.com/microcosm-cc/bluemonday" "net/http" _ "net/http/pprof" "regexp" "runtime" "sync" ) // Current instances var runninginstances map[string]RunningInstance var ri_mutex = &sync.Mutex{} var pool *pgxpool.Pool func startpprof() { logInfo.Print("Starting http/pprof on :7777") logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil)) } func main() { // Initial Setup logInit() runninginstances = make(map[string]RunningInstance) getSettings() if len(settings.Proxies) > 0 { for i := 0; i < len(settings.Proxies); i++ { logInfo.Printf("Using proxy: %s:%d", settings.Proxies[i].Host, settings.Proxies[i].Port) } } go startpprof() pool = getDbPool() p = bluemonday.NewPolicy() spaceReg = regexp.MustCompile(`[\s\t\.]+`) removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`) re = regexp.MustCompile("^https?://([^/]*)/(.*)$") matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*") for _, endpoint := range settings.Autostart { logInfo.Print("Autostarting " + endpoint) ri_mutex.Lock() _, exists := runninginstances[endpoint] if exists == false { runninginstances[endpoint] = RunningInstance{} go StartInstance(endpoint) } ri_mutex.Unlock() } go startctl() go webmain() runtime.Goexit() }