all repos — flounder @ feb2de12f73c40fac2bd635e75fb0b2b97d0f558

A small site builder for the Gemini protocol

main.go (view raw)

 1package main
 2
 3import (
 4	"flag"
 5	"fmt"
 6	// "github.com/go-co-op/gocron"
 7	"github.com/gorilla/sessions"
 8	"io"
 9	"log"
10	"os"
11	"sync"
12	// "time"
13)
14
15var c Config // global var to hold static configuration
16
17func main() {
18	configPath := flag.String("c", "flounder.toml", "path to config file") // doesnt work atm
19	flag.Parse()
20	args := flag.Args()
21	if len(args) < 1 {
22		fmt.Println("expected 'admin' or 'serve' subcommand")
23		os.Exit(1)
24	}
25
26	var err error
27	c, err = getConfig(*configPath)
28	if err != nil {
29		log.Fatal(err)
30	}
31	logFile, err := os.OpenFile(c.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
32	if err != nil {
33		panic(err)
34	}
35	mw := io.MultiWriter(os.Stdout, logFile)
36	log.SetOutput(mw)
37
38	initializeDB()
39
40	cookie := generateCookieKeyIfDNE()
41	SessionStore = sessions.NewCookieStore(cookie)
42	// load domains in memory
43	refreshDomainMap()
44
45	// Background workers
46	if c.AnalyticsDBFile != "" {
47		go dumpLogsWorker()
48	}
49
50	switch args[0] {
51	case "serve":
52		// s1.StartAsync()
53		wg := new(sync.WaitGroup)
54		wg.Add(3)
55		go func() {
56			runHTTPServer()
57			wg.Done()
58		}()
59		go func() {
60			runGeminiServer()
61			wg.Done()
62		}()
63		go func() {
64			runSFTPServer()
65			wg.Done()
66		}()
67		wg.Wait()
68	case "admin":
69		runAdminCommand()
70	case "dumplogs":
71		dumpLogs()
72	}
73}