fedilogue/fedilogue.go
Farhan Khan cd8ecce807 Added proxy support
Some IPv6 traffic still sending directly to instance
not sure why not
2021-01-30 07:12:37 +00:00

60 lines
1.3 KiB
Go

package main
import (
"github.com/jackc/pgx/pgxpool"
"github.com/microcosm-cc/bluemonday"
"net/http"
_ "net/http/pprof"
"regexp"
"runtime"
"sync"
)
// Current instances
var runninginstances map[string]RunningInstance
var ri_mutex = &sync.Mutex{}
var pool *pgxpool.Pool
func startpprof() {
logInfo.Print("Starting http/pprof on :7777")
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
}
func main() {
// Initial Setup
logInit()
runninginstances = make(map[string]RunningInstance)
getSettings()
if len(settings.Proxies) > 0 {
for i := 0; i < len(settings.Proxies); i++ {
logInfo.Printf("Using proxy: %s:%d", settings.Proxies[i].Host, settings.Proxies[i].Port)
}
}
go startpprof()
pool = getDbPool()
p = bluemonday.NewPolicy()
spaceReg = regexp.MustCompile(`[\s\t\.]+`)
removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`)
re = regexp.MustCompile("^https?://([^/]*)/(.*)$")
matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*")
for _, endpoint := range settings.Autostart {
logInfo.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()
}