2021-03-06 09:40:47 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/go-ini/ini"
|
|
|
|
)
|
|
|
|
|
2021-04-12 14:26:49 +00:00
|
|
|
// See https://mycorrhiza.lesarbr.es/hypha/configuration/fields
|
2021-03-06 09:40:47 +00:00
|
|
|
type Config struct {
|
|
|
|
WikiName string
|
|
|
|
NaviTitleIcon string
|
|
|
|
Hyphae
|
|
|
|
Network
|
|
|
|
Authorization
|
|
|
|
}
|
|
|
|
|
|
|
|
type Hyphae struct {
|
|
|
|
HomeHypha string
|
|
|
|
UserHypha string
|
|
|
|
HeaderLinksHypha string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Network struct {
|
|
|
|
HTTPPort uint64
|
|
|
|
URL string
|
|
|
|
GeminiCertificatePath string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Authorization struct {
|
|
|
|
UseFixedAuth bool
|
|
|
|
FixedAuthCredentialsPath string
|
2021-04-12 14:26:49 +00:00
|
|
|
|
|
|
|
UseRegistration bool
|
|
|
|
RegistrationCredentialsPath string
|
|
|
|
LimitRegistration uint64
|
2021-03-06 09:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ReadConfigFile(path string) {
|
|
|
|
cfg := &Config{
|
|
|
|
WikiName: "MycorrhizaWiki",
|
|
|
|
NaviTitleIcon: "🍄",
|
|
|
|
Hyphae: Hyphae{
|
|
|
|
HomeHypha: "home",
|
|
|
|
UserHypha: "u",
|
|
|
|
HeaderLinksHypha: "",
|
|
|
|
},
|
|
|
|
Network: Network{
|
|
|
|
HTTPPort: 1737,
|
|
|
|
URL: "",
|
|
|
|
GeminiCertificatePath: "",
|
|
|
|
},
|
|
|
|
Authorization: Authorization{
|
|
|
|
UseFixedAuth: false,
|
|
|
|
FixedAuthCredentialsPath: "",
|
2021-04-12 14:26:49 +00:00
|
|
|
|
|
|
|
UseRegistration: false,
|
|
|
|
RegistrationCredentialsPath: "",
|
|
|
|
LimitRegistration: 0,
|
2021-03-06 09:40:47 +00:00
|
|
|
},
|
|
|
|
}
|
2021-03-09 14:27:14 +00:00
|
|
|
|
|
|
|
if path != "" {
|
|
|
|
log.Println("Loading config at", path)
|
|
|
|
err := ini.MapTo(cfg, path)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-03-06 09:40:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 14:26:49 +00:00
|
|
|
// Map the struct to the global variables
|
2021-03-06 09:40:47 +00:00
|
|
|
SiteName = cfg.WikiName
|
|
|
|
SiteNavIcon = cfg.NaviTitleIcon
|
|
|
|
HomePage = cfg.HomeHypha
|
|
|
|
UserHypha = cfg.UserHypha
|
|
|
|
HeaderLinksHypha = cfg.HeaderLinksHypha
|
|
|
|
ServerPort = strconv.FormatUint(cfg.HTTPPort, 10)
|
|
|
|
URL = cfg.URL
|
|
|
|
GeminiCertPath = cfg.GeminiCertificatePath
|
|
|
|
UseFixedAuth = cfg.UseFixedAuth
|
|
|
|
FixedCredentialsPath = cfg.FixedAuthCredentialsPath
|
2021-04-12 14:26:49 +00:00
|
|
|
UseRegistration = cfg.UseRegistration
|
|
|
|
RegistrationCredentialsPath = cfg.RegistrationCredentialsPath
|
2021-04-19 16:39:25 +00:00
|
|
|
LimitRegistration = int(cfg.LimitRegistration)
|
2021-03-06 09:40:47 +00:00
|
|
|
}
|