fedilogue/fedilogue.go

57 lines
1.1 KiB
Go

package main
import (
"github.com/microcosm-cc/bluemonday"
"log"
"net/http"
_ "net/http/pprof"
"regexp"
"runtime"
"sync"
)
// Current instances
var runninginstances map[string]RunningInstance
var ri_mutex = &sync.Mutex{}
func startpprof() {
log.Print("Starting http/pprof on :7777")
log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
}
func main() {
// Initial Setup
reportPostChan := make(chan ReportPost)
runninginstances = make(map[string]RunningInstance)
getSettings()
go startpprof()
pool := getDbPool()
for i := 0; i < settings.Database.Workers; i++ {
go postHandler(reportPostChan, pool)
}
p = bluemonday.NewPolicy()
spaceReg = regexp.MustCompile(`\s+`)
for _, endpoint := range settings.Autostart {
log.Print("Autostarting " + endpoint)
ri_mutex.Lock()
_, exists := runninginstances[endpoint]
if exists == true {
log.Print("Already exists: " + endpoint)
} else {
runninginstances[endpoint] = RunningInstance{}
go StartInstance(endpoint, reportPostChan)
}
ri_mutex.Unlock()
}
go startctl(reportPostChan)
go webmain(reportPostChan)
runtime.Goexit()
}