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
29/// Perform some checks to make sure the file is OK
30func checkIfValidFile() {
31}
32
33func getIndexFiles() ([]*File, error) { // cache this function
34 result := []*File{}
35 err := filepath.Walk(userFilesPath, func(path string, info os.FileInfo, err error) error {
36 if err != nil {
37 log.Printf("Failure accessing a path %q: %v\n", path, err)
38 return err // think about
39 }
40 // make this do what it should
41 result = append(result, &File{
42 Name: info.Name(),
43 Creator: "alex",
44 UpdatedTime: "123123",
45 })
46 return nil
47 })
48 if err != nil {
49 return nil, err
50 }
51 // sort
52 // truncate
53 return result, nil
54} // todo clean up paths
55
56func getUserFiles(user string) ([]*File, error) {
57 result := []*File{}
58 files, err := ioutil.ReadDir(path.Join(userFilesPath, user))
59 if err != nil {
60 return nil, err
61 }
62 for _, file := range files {
63 result = append(result, &File{
64 Name: file.Name(),
65 Creator: user,
66 UpdatedTime: "123123",
67 })
68 }
69 return result, nil
70}
71
72func main() {
73 configPath := flag.String("c", "flounder.toml", "path to config file")
74 var err error
75 c, err = getConfig(*configPath)
76 if err != nil {
77 log.Fatal(err)
78 }
79
80 wg := new(sync.WaitGroup)
81 wg.Add(2)
82 go func() {
83 runHTTPServer()
84 wg.Done()
85 }()
86 go func() {
87 runGeminiServer()
88 wg.Done()
89 }()
90 wg.Wait()
91}