all repos — flounder @ d865a8dbc32bcff967a9cf8733d2eda2f36f4889

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)
11
12const ( // todo make configurable
13	userFilesPath = "./files"
14)
15
16type File struct {
17	Creator     string
18	Name        string
19	UpdatedTime string
20}
21
22func getUsers() ([]string, error) {
23	return []string{"me", "other guy"}, nil
24}
25
26func getIndexFiles() ([]*File, error) { // cache this function
27	result := []*File{}
28	err := filepath.Walk(userFilesPath, func(path string, info os.FileInfo, err error) error {
29		if err != nil {
30			log.Printf("Failure accessing a path %q: %v\n", path, err)
31			return err // think about
32		}
33		// make this do what it should
34		result = append(result, &File{
35			Name:        info.Name(),
36			Creator:     "alex",
37			UpdatedTime: "123123",
38		})
39		return nil
40	})
41	if err != nil {
42		return nil, err
43	}
44	// sort
45	// truncate
46	return result, nil
47} // todo clean up paths
48
49func getUserFiles(user string) ([]*File, error) {
50	result := []*File{}
51	files, err := ioutil.ReadDir(path.Join(userFilesPath, user))
52	if err != nil {
53		return nil, err
54	}
55	for _, file := range files {
56		result = append(result, &File{
57			Name:        file.Name(),
58			Creator:     user,
59			UpdatedTime: "123123",
60		})
61	}
62	return result, nil
63}
64
65func main() {
66	configPath := flag.String("c", "flounder.toml", "path to config file")
67	config, err := getConfig(*configPath)
68	if err != nil {
69		log.Fatal(err)
70	}
71	runHTTPServer(&config)
72	// runGeminiServer(&config)
73	// go log.Fatal(gmi.ListenAndServe(":8080", nil))
74}