main.go (view raw)
1package main
2
3import (
4 "io/ioutil"
5 "log"
6 "os"
7 "path"
8 "path/filepath"
9)
10
11const ( // todo make configurable
12 userFilesPath = "./files"
13)
14
15type File struct {
16 Creator string
17 Name string
18 UpdatedTime string
19}
20
21func getIndexFiles() ([]*File, error) { // cache this function
22 result := []*File{}
23 err := filepath.Walk(userFilesPath, func(path string, info os.FileInfo, err error) error {
24 if err != nil {
25 log.Printf("Failure accessing a path %q: %v\n", path, err)
26 return err // think about
27 }
28 // make this do what it should
29 result = append(result, &File{
30 Name: info.Name(),
31 Creator: "alex",
32 UpdatedTime: "123123",
33 })
34 return nil
35 })
36 if err != nil {
37 return nil, err
38 }
39 // sort
40 // truncate
41 return result, nil
42} // todo clean up paths
43
44func getUserFiles(user string) ([]*File, error) {
45 result := []*File{}
46 files, err := ioutil.ReadDir(path.Join(userFilesPath, user))
47 if err != nil {
48 return nil, err
49 }
50 for _, file := range files {
51 result = append(result, &File{
52 Name: file.Name(),
53 Creator: user,
54 UpdatedTime: "123123",
55 })
56 }
57 return result, nil
58}
59
60func main() {
61 // http functions
62 // go serve gemini
63 // go serve http -- not
64 // runHTTPServer()
65 runGeminiServer()
66 // go log.Fatal(gmi.ListenAndServe(":8080", nil))
67}