fedilogue/fedilogue.go

52 lines
942 B
Go

package main
import (
"github.com/microcosm-cc/bluemonday"
"log"
"net/http"
_ "net/http/pprof"
"regexp"
"runtime"
"sync"
"github.com/jackc/pgx/pgxpool"
)
// Current instances
var runninginstances map[string]RunningInstance
var ri_mutex = &sync.Mutex{}
var pool *pgxpool.Pool
func startpprof() {
log.Print("Starting http/pprof on :7777")
log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
}
func main() {
// Initial Setup
runninginstances = make(map[string]RunningInstance)
getSettings()
go startpprof()
pool = getDbPool()
p = bluemonday.NewPolicy()
spaceReg = regexp.MustCompile(`\s+`)
for _, endpoint := range settings.Autostart {
log.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()
}