all repos — flounder @ f282a3b485f2bbe813913fc8e61edc5cc6370161

A small site builder for the Gemini protocol

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