fedilogue/poll/fedilogue.go

55 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
_ "net/http/pprof"
"net/http"
"sync"
2020-12-06 18:05:17 -05:00
"regexp"
"log"
2020-12-06 18:05:17 -05:00
"github.com/microcosm-cc/bluemonday"
)
// Current instances
var runninginstances map[string]RunningInstance
var ri_mutex = &sync.Mutex{}
2020-11-24 20:36:47 -05:00
func startpprof() {
log.Print("Starting http/pprof on :7777")
log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
}
2020-11-24 20:36:47 -05:00
func main() {
// Initial Setup
2020-11-16 00:10:33 -05:00
reportPostChan := make(chan ReportPost)
2020-11-24 20:36:47 -05:00
runninginstances = make(map[string]RunningInstance)
getSettings()
2020-11-24 20:36:47 -05:00
go startpprof()
2020-11-16 00:10:33 -05:00
2020-11-24 20:36:47 -05:00
pool := get_db_pool()
2020-12-06 18:05:17 -05:00
p = bluemonday.NewPolicy()
spaceReg = regexp.MustCompile(`\s+`)
2020-11-24 20:36:47 -05:00
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()
}
2020-11-24 20:36:47 -05:00
go webmain(reportPostChan)
for { // Write posts
v := <-reportPostChan
2020-11-17 22:35:59 -05:00
go writePost(pool, v)
}
}