all repos — flounder @ 6888b8e79940eb9e79dc8edc4b55998e94d46911

A small site builder for the Gemini protocol

main.go (view raw)

 1package main
 2
 3import (
 4	"flag"
 5	"io/ioutil"
 6	"log"
 7	"os"
 8	"path"
 9	"path/filepath"
10	"sync"
11)
12
13var c Config // global var to hold static configuration
14
15const ( // todo make configurable
16	userFilesPath = "./files"
17)
18
19type File struct {
20	Creator     string
21	Name        string
22	UpdatedTime string
23}
24
25func getUsers() ([]string, error) {
26	return []string{"me", "other guy"}, nil
27}
28
29func getIndexFiles() ([]*File, error) { // cache this function
30	result := []*File{}
31	err := filepath.Walk(userFilesPath, func(path string, info os.FileInfo, err error) error {
32		if err != nil {
33			log.Printf("Failure accessing a path %q: %v\n", path, err)
34			return err // think about
35		}
36		// make this do what it should
37		result = append(result, &File{
38			Name:        info.Name(),
39			Creator:     "alex",
40			UpdatedTime: "123123",
41		})
42		return nil
43	})
44	if err != nil {
45		return nil, err
46	}
47	// sort
48	// truncate
49	return result, nil
50} // todo clean up paths
51
52func getUserFiles(user string) ([]*File, error) {
53	result := []*File{}
54	files, err := ioutil.ReadDir(path.Join(userFilesPath, user))
55	if err != nil {
56		return nil, err
57	}
58	for _, file := range files {
59		result = append(result, &File{
60			Name:        file.Name(),
61			Creator:     user,
62			UpdatedTime: "123123",
63		})
64	}
65	return result, nil
66}
67
68func main() {
69	configPath := flag.String("c", "flounder.toml", "path to config file")
70	var err error
71	c, err = getConfig(*configPath)
72	if err != nil {
73		log.Fatal(err)
74	}
75
76	wg := new(sync.WaitGroup)
77	wg.Add(2)
78	go func() {
79		runHTTPServer()
80		wg.Done()
81	}()
82	go func() {
83		runGeminiServer()
84		wg.Done()
85	}()
86	wg.Wait()
87}