fedilogue/poll/main.go

51 lines
961 B
Go

package main
import (
_ "net/http/pprof"
"net/http"
"sync"
"log"
)
// 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()
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)
}
}