diff --git a/util/config.go b/cfg/config.go
similarity index 58%
rename from util/config.go
rename to cfg/config.go
index 6b1212e..09f4088 100644
--- a/util/config.go
+++ b/cfg/config.go
@@ -1,4 +1,4 @@
-package util
+package cfg
import (
"log"
@@ -8,7 +8,31 @@ import (
"github.com/go-ini/ini"
)
-// See https://mycorrhiza.lesarbr.es/hypha/configuration/fields
+var (
+ WikiName string
+ NaviTitleIcon string
+
+ HomeHypha string
+ UserHypha string
+ HeaderLinksHypha string
+
+ HTTPPort string
+ URL string
+ GeminiCertificatePath string
+
+ WikiDir string
+ ConfigFilePath string
+
+ UseFixedAuth bool
+ FixedAuthCredentialsPath string
+ UseRegistration bool
+ RegistrationCredentialsPath string
+ LimitRegistration int
+)
+
+// Config represents a Mycorrhiza wiki configuration file.
+//
+// See https://mycorrhiza.lesarbr.es/hypha/configuration/fields for fields' docs.
type Config struct {
WikiName string
NaviTitleIcon string
@@ -17,18 +41,21 @@ type Config struct {
Authorization
}
+// Hyphae is a section of Config which has fields related to special hyphae.
type Hyphae struct {
HomeHypha string
UserHypha string
HeaderLinksHypha string
}
+// Network is a section of Config that has fields related to network stuff: HTTP and Gemini.
type Network struct {
HTTPPort uint64
URL string
GeminiCertificatePath string
}
+// Authorization is a section of Config that has fields related to authorization and authentication.
type Authorization struct {
UseFixedAuth bool
FixedAuthCredentialsPath string
@@ -38,6 +65,7 @@ type Authorization struct {
LimitRegistration uint64
}
+// ReadConfigFile reads a config on the given path and stores the configuration.
func ReadConfigFile(path string) {
cfg := &Config{
WikiName: "MycorrhizaWiki",
@@ -76,16 +104,16 @@ func ReadConfigFile(path string) {
}
// Map the struct to the global variables
- SiteName = cfg.WikiName
- SiteNavIcon = cfg.NaviTitleIcon
- HomePage = cfg.HomeHypha
+ WikiName = cfg.WikiName
+ NaviTitleIcon = cfg.NaviTitleIcon
+ HomeHypha = cfg.HomeHypha
UserHypha = cfg.UserHypha
HeaderLinksHypha = cfg.HeaderLinksHypha
- ServerPort = strconv.FormatUint(cfg.HTTPPort, 10)
+ HTTPPort = strconv.FormatUint(cfg.HTTPPort, 10)
URL = cfg.URL
- GeminiCertPath = cfg.GeminiCertificatePath
+ GeminiCertificatePath = cfg.GeminiCertificatePath
UseFixedAuth = cfg.UseFixedAuth
- FixedCredentialsPath = cfg.FixedAuthCredentialsPath
+ FixedAuthCredentialsPath = cfg.FixedAuthCredentialsPath
UseRegistration = cfg.UseRegistration
RegistrationCredentialsPath = cfg.RegistrationCredentialsPath
LimitRegistration = int(cfg.LimitRegistration)
diff --git a/files/files.go b/files/files.go
index 5f03a10..634cc16 100644
--- a/files/files.go
+++ b/files/files.go
@@ -3,11 +3,11 @@ package files
import (
"errors"
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"path/filepath"
"strings"
"github.com/adrg/xdg"
- "github.com/bouncepaw/mycorrhiza/util"
"github.com/mitchellh/go-homedir"
)
@@ -49,7 +49,7 @@ func tokenStoragePath() (string, error) {
if err != nil {
return "", err
}
- if strings.HasPrefix(dir, util.WikiDir) {
+ if strings.HasPrefix(dir, cfg.WikiDir) {
return "", errors.New("wiki storage directory includes private config files")
}
return dir, nil
@@ -57,7 +57,7 @@ func tokenStoragePath() (string, error) {
func registrationCredentialsPath() (string, error) {
var err error
- path := util.RegistrationCredentialsPath
+ path := cfg.RegistrationCredentialsPath
if len(path) == 0 {
path, err = xdg.DataFile("mycorrhiza/registration.json")
@@ -81,7 +81,7 @@ func registrationCredentialsPath() (string, error) {
func fixedCredentialsPath() (string, error) {
var err error
- path := util.FixedCredentialsPath
+ path := cfg.FixedAuthCredentialsPath
if len(path) > 0 {
path, err = homedir.Expand(path)
diff --git a/flag.go b/flag.go
index 6cb3fef..35bb9da 100644
--- a/flag.go
+++ b/flag.go
@@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"log"
"os"
"path/filepath"
@@ -14,7 +15,7 @@ import (
var printExampleConfig bool
func init() {
- flag.StringVar(&util.ConfigFilePath, "config-path", "", "Path to a configuration file. Leave empty if you don't want to use it.")
+ flag.StringVar(&cfg.ConfigFilePath, "config-path", "", "Path to a configuration file. Leave empty if you don't want to use it.")
flag.BoolVar(&printExampleConfig, "print-example-config", false, "If true, print an example configuration file contents and exit. You can save the output to a file and base your own configuration on it.")
flag.Usage = func() {
fmt.Fprintf(
@@ -42,16 +43,16 @@ func parseCliArgs() {
var err error
WikiDir, err = filepath.Abs(args[0])
- util.WikiDir = WikiDir
+ cfg.WikiDir = WikiDir
if err != nil {
log.Fatal(err)
}
- if util.URL == "" {
- util.URL = "http://0.0.0.0:" + util.ServerPort
+ if cfg.URL == "" {
+ cfg.URL = "http://0.0.0.0:" + cfg.HTTPPort
}
- util.HomePage = util.CanonicalName(util.HomePage)
- util.UserHypha = util.CanonicalName(util.UserHypha)
- util.HeaderLinksHypha = util.CanonicalName(util.HeaderLinksHypha)
+ cfg.HomeHypha = util.CanonicalName(cfg.HomeHypha)
+ cfg.UserHypha = util.CanonicalName(cfg.UserHypha)
+ cfg.HeaderLinksHypha = util.CanonicalName(cfg.HeaderLinksHypha)
}
diff --git a/gemini.go b/gemini.go
index b86c3a4..050edc1 100644
--- a/gemini.go
+++ b/gemini.go
@@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"crypto/x509/pkix"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"log"
"path/filepath"
@@ -13,7 +14,6 @@ import (
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/markup"
- "github.com/bouncepaw/mycorrhiza/util"
)
func geminiHomeHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
@@ -23,7 +23,7 @@ func geminiHomeHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
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/` + util.HomePage))
+=> /hypha/` + cfg.HomeHypha))
}
func geminiHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
@@ -48,10 +48,10 @@ func geminiHypha(w *gemini.ResponseWriter, rq *gemini.Request) {
}
func handleGemini() {
- if util.GeminiCertPath == "" {
+ if cfg.GeminiCertificatePath == "" {
return
}
- certPath, err := filepath.Abs(util.GeminiCertPath)
+ certPath, err := filepath.Abs(cfg.GeminiCertificatePath)
if err != nil {
log.Fatal(err)
}
diff --git a/history/history.go b/history/history.go
index dd53203..b94ee51 100644
--- a/history/history.go
+++ b/history/history.go
@@ -3,6 +3,7 @@ package history
import (
"bytes"
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"html"
"log"
"os/exec"
@@ -167,7 +168,7 @@ func (rev *Revision) bestLink() string {
func gitsh(args ...string) (out bytes.Buffer, err error) {
fmt.Printf("$ %v\n", args)
cmd := exec.Command(gitpath, args...)
- cmd.Dir = util.WikiDir
+ cmd.Dir = cfg.WikiDir
b, err := cmd.CombinedOutput()
if err != nil {
@@ -179,7 +180,7 @@ func gitsh(args ...string) (out bytes.Buffer, err error) {
// silentGitsh is like gitsh, except it writes less to the stdout.
func silentGitsh(args ...string) (out bytes.Buffer, err error) {
cmd := exec.Command(gitpath, args...)
- cmd.Dir = util.WikiDir
+ cmd.Dir = cfg.WikiDir
b, err := cmd.CombinedOutput()
return *bytes.NewBuffer(b), err
diff --git a/history/information.go b/history/information.go
index 75b7501..0570e6e 100644
--- a/history/information.go
+++ b/history/information.go
@@ -4,20 +4,20 @@ package history
import (
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"log"
"regexp"
"strconv"
"strings"
"time"
- "github.com/bouncepaw/mycorrhiza/util"
"github.com/gorilla/feeds"
)
func recentChangesFeed() *feeds.Feed {
feed := &feeds.Feed{
Title: "Recent changes",
- Link: &feeds.Link{Href: util.URL},
+ Link: &feeds.Link{Href: cfg.URL},
Description: "List of 30 recent changes on the wiki",
Author: &feeds.Author{Name: "Wikimind", Email: "wikimind@mycorrhiza"},
Updated: time.Now(),
@@ -44,7 +44,7 @@ func recentChangesFeed() *feeds.Feed {
Description: rev.descriptionForFeed(),
Created: rev.Time,
Updated: rev.Time,
- Link: &feeds.Link{Href: util.URL + rev.bestLink()},
+ Link: &feeds.Link{Href: cfg.URL + rev.bestLink()},
})
}
return feed
@@ -141,7 +141,7 @@ func (rev *Revision) asHistoryEntry(hyphaName string) (html string) {
author := ""
if rev.Username != "anon" {
author = fmt.Sprintf(`
- by %[2]s`, util.UserHypha, rev.Username)
+ by %[2]s`, cfg.UserHypha, rev.Username)
}
return fmt.Sprintf(`
@@ -176,7 +176,7 @@ func parseRevisionLine(line string) Revision {
// See how the file with `filepath` looked at commit with `hash`.
func FileAtRevision(filepath, hash string) (string, error) {
- out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, util.WikiDir+"/"))
+ out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/"))
return out.String(), err
}
diff --git a/http_admin.go b/http_admin.go
index 286d5af..d4d1612 100644
--- a/http_admin.go
+++ b/http_admin.go
@@ -1,11 +1,11 @@
package main
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"log"
"net/http"
"github.com/bouncepaw/mycorrhiza/user"
- "github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
@@ -38,6 +38,6 @@ func handlerAdminReindexUsers(w http.ResponseWriter, rq *http.Request) {
prepareRq(rq)
if user.CanProceed(rq, "admin") && rq.Method == "POST" {
user.ReadUsersFromFilesystem()
- http.Redirect(w, rq, "/hypha/"+util.UserHypha, http.StatusSeeOther)
+ http.Redirect(w, rq, "/hypha/"+cfg.UserHypha, http.StatusSeeOther)
}
}
diff --git a/http_auth.go b/http_auth.go
index 4028495..fb0337f 100644
--- a/http_auth.go
+++ b/http_auth.go
@@ -1,6 +1,7 @@
package main
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io"
"log"
"net/http"
@@ -20,7 +21,7 @@ func init() {
func handlerRegister(w http.ResponseWriter, rq *http.Request) {
prepareRq(rq)
- if !util.UseRegistration {
+ if !cfg.UseRegistration {
w.WriteHeader(http.StatusForbidden)
}
if rq.Method == http.MethodGet {
diff --git a/http_stuff.go b/http_stuff.go
index 5ca70d4..8984fc1 100644
--- a/http_stuff.go
+++ b/http_stuff.go
@@ -2,6 +2,7 @@
package main
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io"
"log"
"math/rand"
@@ -32,7 +33,7 @@ func handlerList(w http.ResponseWriter, rq *http.Request) {
func handlerReindex(w http.ResponseWriter, rq *http.Request) {
prepareRq(rq)
if ok := user.CanProceed(rq, "reindex"); !ok {
- HttpErr(w, http.StatusForbidden, util.HomePage, "Not enough rights", "You must be an admin to reindex hyphae.")
+ HttpErr(w, http.StatusForbidden, cfg.HomeHypha, "Not enough rights", "You must be an admin to reindex hyphae.")
log.Println("Rejected", rq.URL)
return
}
@@ -50,7 +51,7 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) {
func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) {
prepareRq(rq)
if ok := user.CanProceed(rq, "update-header-links"); !ok {
- HttpErr(w, http.StatusForbidden, util.HomePage, "Not enough rights", "You must be a moderator to update header links.")
+ HttpErr(w, http.StatusForbidden, cfg.HomeHypha, "Not enough rights", "You must be a moderator to update header links.")
log.Println("Rejected", rq.URL)
return
}
@@ -66,7 +67,7 @@ func handlerRandom(w http.ResponseWriter, rq *http.Request) {
amountOfHyphae = hyphae.Count()
)
if amountOfHyphae == 0 {
- HttpErr(w, http.StatusNotFound, util.HomePage, "There are no hyphae",
+ HttpErr(w, http.StatusNotFound, cfg.HomeHypha, "There are no hyphae",
"It is impossible to display a random hypha because the wiki does not contain any hyphae")
return
}
@@ -84,7 +85,7 @@ func handlerRandom(w http.ResponseWriter, rq *http.Request) {
func handlerAbout(w http.ResponseWriter, rq *http.Request) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
- _, err := io.WriteString(w, base("About "+util.SiteName, views.AboutHTML(), user.FromRequest(rq)))
+ _, err := io.WriteString(w, base("About "+cfg.WikiName, views.AboutHTML(), user.FromRequest(rq)))
if err != nil {
log.Println(err)
}
diff --git a/main.go b/main.go
index d358c39..1d17db2 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ package main
import (
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"log"
"net/http"
@@ -19,7 +20,6 @@ import (
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/shroom"
"github.com/bouncepaw/mycorrhiza/user"
- "github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
@@ -52,13 +52,13 @@ var base = views.BaseHTML
func handlerStyle(w http.ResponseWriter, rq *http.Request) {
prepareRq(rq)
- if _, err := os.Stat(util.WikiDir + "/static/common.css"); err == nil {
- http.ServeFile(w, rq, util.WikiDir+"/static/common.css")
+ if _, err := os.Stat(cfg.WikiDir + "/static/common.css"); err == nil {
+ http.ServeFile(w, rq, cfg.WikiDir+"/static/common.css")
} else {
w.Header().Set("Content-Type", "text/css;charset=utf-8")
w.Write([]byte(assets.DefaultCSS()))
}
- if bytes, err := ioutil.ReadFile(util.WikiDir + "/static/custom.css"); err == nil {
+ if bytes, err := ioutil.ReadFile(cfg.WikiDir + "/static/custom.css"); err == nil {
w.Write(bytes)
}
}
@@ -124,7 +124,7 @@ func main() {
parseCliArgs()
// It is ok if the path is ""
- util.ReadConfigFile(util.ConfigFilePath)
+ cfg.ReadConfigFile(cfg.ConfigFilePath)
if err := files.CalculatePaths(); err != nil {
log.Fatal(err)
@@ -163,9 +163,9 @@ func main() {
http.HandleFunc("/static/icon/", handlerIcon)
http.HandleFunc("/robots.txt", handlerRobotsTxt)
http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
- addr, _ := url.Parse("/hypha/" + util.HomePage) // Let's pray it never fails
+ addr, _ := url.Parse("/hypha/" + cfg.HomeHypha) // Let's pray it never fails
rq.URL = addr
handlerHypha(w, rq)
})
- log.Fatal(http.ListenAndServe("0.0.0.0:"+util.ServerPort, nil))
+ log.Fatal(http.ListenAndServe("0.0.0.0:"+cfg.HTTPPort, nil))
}
diff --git a/markup/mycomarkup.go b/markup/mycomarkup.go
index 2fadd4e..ae8ddc3 100644
--- a/markup/mycomarkup.go
+++ b/markup/mycomarkup.go
@@ -3,12 +3,12 @@ package markup
import (
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"html"
"regexp"
"strings"
"github.com/bouncepaw/mycorrhiza/link"
- "github.com/bouncepaw/mycorrhiza/util"
)
// A Mycomarkup-formatted document
@@ -63,14 +63,14 @@ func (md *MycoDoc) OpenGraphHTML() string {
ogTag("title", md.hyphaName),
ogTag("type", "article"),
ogTag("image", md.firstImageURL),
- ogTag("url", util.URL+"/hypha/"+md.hyphaName),
+ ogTag("url", cfg.URL+"/hypha/"+md.hyphaName),
ogTag("determiner", ""),
ogTag("description", htmlTagRe.ReplaceAllString(md.description, "")),
}, "\n")
}
func (md *MycoDoc) ogFillVars() *MycoDoc {
- md.firstImageURL = util.URL + "/favicon.ico"
+ md.firstImageURL = cfg.URL + "/favicon.ico"
foundDesc := false
foundImg := false
for _, line := range md.ast {
@@ -84,7 +84,7 @@ func (md *MycoDoc) ogFillVars() *MycoDoc {
if !foundImg && len(v.entries) > 0 {
md.firstImageURL = v.entries[0].srclink.ImgSrc()
if v.entries[0].srclink.Kind != link.LinkExternal {
- md.firstImageURL = util.URL + md.firstImageURL
+ md.firstImageURL = cfg.URL + md.firstImageURL
}
foundImg = true
}
diff --git a/name.go b/name.go
index 59bd9fc..fd2a742 100644
--- a/name.go
+++ b/name.go
@@ -1,6 +1,7 @@
package main
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"log"
"net/http"
"strings"
@@ -19,7 +20,7 @@ func HyphaNameFromRq(rq *http.Request, actions ...string) string {
}
}
log.Println("HyphaNameFromRq: this request is invalid, fallback to home hypha")
- return util.HomePage
+ return cfg.HomeHypha
}
// 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".
diff --git a/shroom/init.go b/shroom/init.go
index 96a6195..f5e28f1 100644
--- a/shroom/init.go
+++ b/shroom/init.go
@@ -2,10 +2,10 @@ package shroom
import (
"errors"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/markup"
- "github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
@@ -31,8 +31,8 @@ func init() {
}
markup.HyphaImageForOG = func(hyphaName string) string {
if h := hyphae.ByName(hyphaName); h.Exists && h.BinaryPath != "" {
- return util.URL + "/binary/" + hyphaName
+ return cfg.URL + "/binary/" + hyphaName
}
- return util.URL + "/favicon.ico"
+ return cfg.URL + "/favicon.ico"
}
}
diff --git a/shroom/upload.go b/shroom/upload.go
index c72ec9a..92fb51d 100644
--- a/shroom/upload.go
+++ b/shroom/upload.go
@@ -3,6 +3,7 @@ package shroom
import (
"errors"
"fmt"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"log"
"mime/multipart"
@@ -13,7 +14,6 @@ import (
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/mimetype"
"github.com/bouncepaw/mycorrhiza/user"
- "github.com/bouncepaw/mycorrhiza/util"
)
func UploadText(h *hyphae.Hypha, data []byte, u *user.User) (hop *history.HistoryOp, errtitle string) {
@@ -56,7 +56,7 @@ func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.Use
// uploadHelp is a helper function for UploadText and UploadBinary
func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte, u *user.User) (*history.HistoryOp, string) {
var (
- fullPath = filepath.Join(util.WikiDir, h.Name+ext)
+ fullPath = filepath.Join(cfg.WikiDir, h.Name+ext)
originalFullPath = &h.TextPath
)
if hop.Type == history.TypeEditBinary {
diff --git a/shroom/view.go b/shroom/view.go
index 05becb9..b00bf75 100644
--- a/shroom/view.go
+++ b/shroom/view.go
@@ -1,6 +1,7 @@
package shroom
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"os"
@@ -24,7 +25,7 @@ func FetchTextPart(h *hyphae.Hypha) (string, error) {
}
func SetHeaderLinks() {
- if userLinksHypha := hyphae.ByName(util.HeaderLinksHypha); !userLinksHypha.Exists {
+ if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists {
util.SetDefaultHeaderLinks()
} else {
contents, err := ioutil.ReadFile(userLinksHypha.TextPath)
diff --git a/user/files.go b/user/files.go
index c1f0172..a76f086 100644
--- a/user/files.go
+++ b/user/files.go
@@ -2,30 +2,30 @@ package user
import (
"encoding/json"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"log"
"os"
"github.com/bouncepaw/mycorrhiza/files"
- "github.com/bouncepaw/mycorrhiza/util"
)
// InitUserDatabase checks the configuration for auth methods and loads users
// if necessary. Call it during initialization.
func InitUserDatabase() {
- AuthUsed = util.UseFixedAuth || util.UseRegistration
+ AuthUsed = cfg.UseFixedAuth || cfg.UseRegistration
- if AuthUsed && (util.FixedCredentialsPath != "" || util.RegistrationCredentialsPath != "") {
+ if AuthUsed && (cfg.FixedAuthCredentialsPath != "" || cfg.RegistrationCredentialsPath != "") {
ReadUsersFromFilesystem()
}
}
// ReadUsersFromFilesystem reads all user information from filesystem and stores it internally.
func ReadUsersFromFilesystem() {
- if util.UseFixedAuth {
+ if cfg.UseFixedAuth {
rememberUsers(usersFromFixedCredentials())
}
- if util.UseRegistration {
+ if cfg.UseRegistration {
rememberUsers(usersFromRegistrationCredentials())
}
readTokensToUsers()
diff --git a/user/net.go b/user/net.go
index 88ef769..3703087 100644
--- a/user/net.go
+++ b/user/net.go
@@ -2,6 +2,7 @@ package user
import (
"errors"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"log"
"net/http"
"strconv"
@@ -39,8 +40,8 @@ func Register(username, password string) error {
username = util.CanonicalName(username)
log.Println("Attempt to register user", username)
switch {
- case CountRegistered() >= util.LimitRegistration && util.LimitRegistration > 0:
- i := strconv.Itoa(util.LimitRegistration)
+ case CountRegistered() >= cfg.LimitRegistration && cfg.LimitRegistration > 0:
+ i := strconv.Itoa(cfg.LimitRegistration)
log.Println("Limit reached: " + i)
return errors.New("Reached the limit of registered users: " + i)
case HasUsername(username):
diff --git a/util/header_links.go b/util/header_links.go
index c574768..bc942c7 100644
--- a/util/header_links.go
+++ b/util/header_links.go
@@ -1,12 +1,13 @@
package util
import (
+ "github.com/bouncepaw/mycorrhiza/cfg"
"strings"
)
func SetDefaultHeaderLinks() {
HeaderLinks = []HeaderLink{
- {"/", SiteName},
+ {"/", cfg.WikiName},
{"/recent-changes", "Recent changes"},
{"/list", "All hyphae"},
{"/random", "Random"},
@@ -18,7 +19,7 @@ func ParseHeaderLinks(text string, rocketlinkλ func(string, string) (string, st
HeaderLinks = []HeaderLink{}
for _, line := range strings.Split(text, "\n") {
if strings.HasPrefix(line, "=>") {
- href, text, _ := rocketlinkλ(line, HeaderLinksHypha)
+ href, text, _ := rocketlinkλ(line, cfg.HeaderLinksHypha)
HeaderLinks = append(HeaderLinks, HeaderLink{
Href: href,
Display: text,
diff --git a/util/util.go b/util/util.go
index 5a685ca..92fcd68 100644
--- a/util/util.go
+++ b/util/util.go
@@ -3,35 +3,13 @@ package util
import (
"crypto/rand"
"encoding/hex"
+ "github.com/bouncepaw/mycorrhiza/cfg"
"net/http"
"regexp"
"strings"
"unicode"
)
-// TODO: make names match to fields of config file
-var (
- SiteName string
- SiteNavIcon string
-
- HomePage string
- UserHypha string
- HeaderLinksHypha string
-
- ServerPort string
- URL string
- GeminiCertPath string
-
- WikiDir string
- ConfigFilePath string
-
- UseFixedAuth bool
- FixedCredentialsPath string
- UseRegistration bool
- RegistrationCredentialsPath string
- LimitRegistration int
-)
-
// LettersNumbersOnly keeps letters and numbers only in the given string.
func LettersNumbersOnly(s string) string {
var (
@@ -52,8 +30,8 @@ func LettersNumbersOnly(s string) 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 strings.HasPrefix(path, cfg.WikiDir) {
+ tmp := strings.TrimPrefix(path, cfg.WikiDir)
if tmp == "" {
return ""
}
@@ -103,9 +81,9 @@ func CanonicalName(name string) string {
}
// HyphaPattern is a pattern which all hyphae must match.
-var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"\'&%{}]+`)
+var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"'&%{}]+`)
-var UsernamePattern = regexp.MustCompile(`[^?!:#@><*|"\'&%{}/]+`)
+var UsernamePattern = regexp.MustCompile(`[^?!:#@><*|"'&%{}/]+`)
// IsCanonicalName checks if the `name` is canonical.
func IsCanonicalName(name string) bool {
diff --git a/views/auth.qtpl b/views/auth.qtpl
index 2cf72ae..94f67fa 100644
--- a/views/auth.qtpl
+++ b/views/auth.qtpl
@@ -1,15 +1,15 @@
{% import "net/http" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
-{% import "github.com/bouncepaw/mycorrhiza/util" %}
+{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% func RegisterHTML(rq *http.Request) %}
- {% if util.UseRegistration %}
+ {% if cfg.UseRegistration %}
- {% elseif util.UseFixedAuth %}
+ {% elseif cfg.UseFixedAuth %}
Administrators have forbidden registration for this wiki. Administrators can make an account for you by hand; contact them.
← Go back
{% else %}
@@ -43,7 +43,7 @@
{% if user.AuthUsed %}
@@ -95,16 +96,16 @@ for u := range user.YieldUsers() {
- About {%s util.SiteName %}
+ About {%s cfg.WikiName %}
- MycorrhizaWiki version: 1.2.0 indev
{%- if user.AuthUsed -%}
- User count: {%d user.Count() %}
- - Home page: {%s util.HomePage %}
+ - Home page: {%s cfg.HomeHypha %}
- Administrators: {%- for i, username := range user.ListUsersWithGroup("admin") -%}
{%- if i > 0 -%},
{%- endif -%}
- {%s username %}{%- endfor -%}
+ {%s username %}{%- endfor -%}
{%- else -%}
- This wiki does not use authorization
{%- endif -%}
diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go
index cd170a0..a2d3de6 100644
--- a/views/stuff.qtpl.go
+++ b/views/stuff.qtpl.go
@@ -8,30 +8,33 @@ package views
import "path/filepath"
//line views/stuff.qtpl:2
-import "github.com/bouncepaw/mycorrhiza/hyphae"
+import "github.com/bouncepaw/mycorrhiza/cfg"
//line views/stuff.qtpl:3
-import "github.com/bouncepaw/mycorrhiza/user"
+import "github.com/bouncepaw/mycorrhiza/hyphae"
//line views/stuff.qtpl:4
+import "github.com/bouncepaw/mycorrhiza/user"
+
+//line views/stuff.qtpl:5
import "github.com/bouncepaw/mycorrhiza/util"
-//line views/stuff.qtpl:6
+//line views/stuff.qtpl:7
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
-//line views/stuff.qtpl:6
+//line views/stuff.qtpl:7
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
-//line views/stuff.qtpl:6
+//line views/stuff.qtpl:7
func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string, u *user.User, headElements ...string) {
-//line views/stuff.qtpl:6
+//line views/stuff.qtpl:7
qw422016.N().S(`
@@ -40,18 +43,18 @@ func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string, u *user.User,
`)
-//line views/stuff.qtpl:13
+//line views/stuff.qtpl:14
qw422016.E().S(title)
-//line views/stuff.qtpl:13
+//line views/stuff.qtpl:14
qw422016.N().S(`
`)
-//line views/stuff.qtpl:14
+//line views/stuff.qtpl:15
for _, el := range headElements {
-//line views/stuff.qtpl:14
+//line views/stuff.qtpl:15
qw422016.N().S(el)
-//line views/stuff.qtpl:14
+//line views/stuff.qtpl:15
}
-//line views/stuff.qtpl:14
+//line views/stuff.qtpl:15
qw422016.N().S(`
@@ -59,76 +62,76 @@ func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string, u *user.User,
`)
-//line views/stuff.qtpl:27
+//line views/stuff.qtpl:28
qw422016.N().S(body)
-//line views/stuff.qtpl:27
+//line views/stuff.qtpl:28
qw422016.N().S(`