flounder

A simple gemini site builder
git clone git://git.alexwennerberg.com/flounder
Log | Files | Refs | README | LICENSE

main.go (1204B) - raw


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