fedilogue/poll/main.go

55 lines
1.0 KiB
Go

package main
import (
_ "net/http/pprof"
"net/http"
"sync"
"regexp"
"log"
"github.com/microcosm-cc/bluemonday"
)
// 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 := get_db_pool()
p = bluemonday.NewPolicy()
spaceReg = regexp.MustCompile(`\s+`)
go startctl(reportPostChan)
for _, endpoint := range settings.Autostart {
log.Print("Autostarting " + endpoint)
ri_mutex.Lock()
_, exists := runninginstances[endpoint]
if exists == true {
log.Println("Already exists: " + endpoint)
} else {
runninginstances[endpoint] = RunningInstance{}
go StartInstance(endpoint, reportPostChan)
}
ri_mutex.Unlock()
}
go webmain(reportPostChan)
for { // Write posts
v := <-reportPostChan
go writePost(pool, v)
}
}