all repos — flounder @ 664d07956cd4b2c58ef4bb4414ce7a324555d3f3

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