57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
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)
|
|
_, exists := GetRunner(endpoint)
|
|
if exists == false {
|
|
go StartInstance(endpoint)
|
|
}
|
|
}
|
|
|
|
go startctl()
|
|
go webmain()
|
|
|
|
runtime.Goexit()
|
|
}
|