flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 12355a343f5989021dbad85cff9c72d42e33c017
parent 513b89478a4f33bd6297c94602c71aab17032aac
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 19 Oct 2020 19:52:15 -0700

add skeleton for gemini server

Diffstat:
MREADME.md | 6++++--
Agemini.go | 19+++++++++++++++++++
Mgo.mod | 1+
Mgo.sum | 2++
Ahttp.go | 41+++++++++++++++++++++++++++++++++++++++++
Mmain.go | 34+++++++++++++++++-----------------
6 files changed, 84 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md @@ -1,3 +1,5 @@ -# Flounder in Go +# Flounder -Experimental rewrite of Flounder in Go +A lightweight server to help users build simple Gemini sites over http(s) + +Designed to help make the Gemini ecosystem more accessible. diff --git a/gemini.go b/gemini.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "git.sr.ht/~adnano/gmi" +) + +func gmiIndex(w *gmi.ResponseWriter, r *gmi.Request) { + fmt.Fprintf(w, "index") +} + +func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { +} + +func runGeminiServer() { + var server gmi.Server + server.HandleFunc("flounder.online", gmiIndex) + server.ListenAndServe() +} diff --git a/go.mod b/go.mod @@ -3,6 +3,7 @@ module git.sr.ht/flounder go 1.15 require ( + git.sr.ht/~adnano/gmi v0.1.0-alpha.1 github.com/BurntSushi/toml v0.3.1 github.com/mattn/go-sqlite3 v1.14.4 ) diff --git a/go.sum b/go.sum @@ -1,3 +1,5 @@ +git.sr.ht/~adnano/gmi v0.1.0-alpha.1 h1:5sha5ucev32U95drEEaPw9rm6hGWJtL8y5HViQ3VDJQ= +git.sr.ht/~adnano/gmi v0.1.0-alpha.1/go.mod h1:t/m2KtH+7lXIF7jjVN+bNvwPbE0nxHOpvlA/WZ/KeLQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/mattn/go-sqlite3 v1.14.4 h1:4rQjbDxdu9fSgI/r3KN72G3c2goxknAqHHgPWWs8UlI= diff --git a/http.go b/http.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func indexHandler(w http.ResponseWriter, r *http.Request) { + indexFiles, _ := getIndexFiles() + for _, file := range indexFiles { + fmt.Fprintf(w, "%s\n", file.Name) + } +} + +func editFileHandler(w http.ResponseWriter, r *http.Request) { + // get vs post + // read file content + authUser := "alex" + files, _ := getUserFiles(authUser) + for _, file := range files { + fmt.Fprintf(w, "%s\n", file.Name) + } +} + +func mySiteHandler(w http.ResponseWriter, r *http.Request) { + authUser := "alex" + files, _ := getUserFiles(authUser) + for _, file := range files { + fmt.Fprintf(w, "%s\n", file.Name) + } +} + +func runHTTPServer() { + http.HandleFunc("/", indexHandler) + http.HandleFunc("/my_site", mySiteHandler) + http.HandleFunc("/edit/", editFileHandler) + // http.HandleFunc("/delete/", deleteFileHandler) + // login+register functions + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/main.go b/main.go @@ -1,10 +1,8 @@ package main import ( - "fmt" "io/ioutil" "log" - "net/http" "os" "path" "path/filepath" @@ -41,27 +39,29 @@ func getIndexFiles() ([]*File, error) { // cache this function // sort // truncate return result, nil -} +} // todo clean up paths -func indexHandler(w http.ResponseWriter, r *http.Request) { - indexFiles, _ := getIndexFiles() - for _, file := range indexFiles { - fmt.Fprintf(w, "%s\n", file.Name) +func getUserFiles(user string) ([]*File, error) { + result := []*File{} + files, err := ioutil.ReadDir(path.Join(userFilesPath, user)) + if err != nil { + return nil, err } -} - -func mySiteHandler(w http.ResponseWriter, r *http.Request) { - authUser := "alex" - files, _ := ioutil.ReadDir(path.Join(userFilesPath, authUser)) for _, file := range files { - fmt.Fprintf(w, "%s\n", file.Name()) + result = append(result, &File{ + Name: file.Name(), + Creator: user, + UpdatedTime: "123123", + }) } + return result, nil } func main() { - http.HandleFunc("/", indexHandler) - http.HandleFunc("/my_site", mySiteHandler) + // http functions // go serve gemini - // go serve http - log.Fatal(http.ListenAndServe(":8080", nil)) + // go serve http -- not + // runHTTPServer() + runGeminiServer() + // go log.Fatal(gmi.ListenAndServe(":8080", nil)) }