mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-10-25 12:47:41 +00:00
Refactor and document some stuff
This commit is contained in:
30
gemini.go
30
gemini.go
@@ -1,29 +1,37 @@
|
||||
package main
|
||||
|
||||
// Gemini-related stuff. This is currently a proof-of-concept implementation, no one really uses it.
|
||||
// Maybe we should deprecate it until we find power to do it properly?
|
||||
//
|
||||
// When this stuff gets more serious, a separate module will be needed.
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509/pkix"
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~adnano/go-gemini"
|
||||
"git.sr.ht/~adnano/go-gemini/certificate"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||
"github.com/bouncepaw/mycorrhiza/markup"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
func geminiHomeHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
|
||||
log.Println(rq.URL)
|
||||
w.Write([]byte(`# MycorrhizaWiki
|
||||
_, _ = io.WriteString(w, `# MycorrhizaWiki
|
||||
|
||||
You have successfully served the wiki through Gemini. Currently, support is really work-in-progress; you should resort to using Mycorrhiza through the web protocols.
|
||||
|
||||
Visit home hypha:
|
||||
=> /hypha/` + cfg.HomeHypha))
|
||||
=> /hypha/`+cfg.HomeHypha)
|
||||
}
|
||||
|
||||
func geminiHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
|
||||
@@ -42,9 +50,9 @@ func geminiHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
|
||||
}
|
||||
}
|
||||
if hasAmnt {
|
||||
w.Write([]byte("This hypha has an attachment\n"))
|
||||
_, _ = io.WriteString(w, "This hypha has an attachment\n")
|
||||
}
|
||||
w.Write([]byte(contents))
|
||||
_, _ = io.WriteString(w, contents)
|
||||
}
|
||||
|
||||
func handleGemini() {
|
||||
@@ -82,3 +90,15 @@ func handleGemini() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// geminiHyphaNameFromRq extracts hypha name from gemini request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha".
|
||||
func geminiHyphaNameFromRq(rq *gemini.Request, actions ...string) string {
|
||||
p := rq.URL.Path
|
||||
for _, action := range actions {
|
||||
if strings.HasPrefix(p, "/"+action+"/") {
|
||||
return util.CanonicalName(strings.TrimPrefix(p, "/"+action+"/"))
|
||||
}
|
||||
}
|
||||
log.Fatal("HyphaNameFromRq: no matching action passed")
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user