git.alexw.nyc home about git garden
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
package main

import (
	"flag"
	"fmt"

	// "github.com/go-co-op/gocron"
	"io"
	"log"
	"os"
	"sync"

	"github.com/gorilla/sessions"
	// "time"
)

var c Config // global var to hold static configuration

func main() {
	configPath := flag.String("c", "flounder.toml", "path to config file") // doesnt work atm
	flag.Parse()
	args := flag.Args()
	if len(args) < 1 {
		fmt.Println("expected 'admin' or 'serve' subcommand")
		os.Exit(1)
	}

	var err error
	c, err = getConfig(*configPath)
	if err != nil {
		log.Fatal(err)
	}
	logFile, err := os.OpenFile(c.LogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
	if err != nil {
		panic(err)
	}
	mw := io.MultiWriter(os.Stdout, logFile)
	log.SetOutput(mw)

	initializeDB()

	cookie := generateCookieKeyIfDNE()
	SessionStore = sessions.NewCookieStore(cookie)
	// load domains in memory
	refreshDomainMap()

	switch args[0] {
	case "serve":
		// s1.StartAsync()
		wg := new(sync.WaitGroup)
		wg.Add(3)
		go func() {
			runHTTPServer()
			wg.Done()
		}()
		go func() {
			runGeminiServer()
			wg.Done()
		}()
		go func() {
			runSFTPServer()
			wg.Done()
		}()
		go func() {
			runFingerServer()
			wg.Done()
		}()
		wg.Wait()
	case "admin":
		runAdminCommand()

	}
}