1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/util/util.go

44 lines
1.0 KiB
Go
Raw Normal View History

package util
import (
2020-08-31 17:52:26 +00:00
"net/http"
"strings"
)
2020-10-25 15:06:51 +00:00
var (
ServerPort string
HomePage string
SiteTitle string
WikiDir string
)
// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir.
func ShorterPath(path string) string {
if strings.HasPrefix(path, WikiDir) {
tmp := strings.TrimPrefix(path, WikiDir)
if tmp == "" {
return ""
}
return tmp[1:]
}
return path
}
2020-08-31 17:52:26 +00:00
// HTTP200Page wraps some frequently used things for successful 200 responses.
func HTTP200Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(page))
}
2020-10-03 16:56:56 +00:00
// FindSubhyphae finds names of existing hyphae given the `hyphaIterator`.
func FindSubhyphae(hyphaName string, hyphaIterator func(func(string))) []string {
subhyphae := make([]string, 0)
hyphaIterator(func(otherHyphaName string) {
if strings.HasPrefix(otherHyphaName, hyphaName+"/") {
subhyphae = append(subhyphae, otherHyphaName)
}
})
return subhyphae
}