mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
Remove log.Fatal invokations from ReadConfigFile()
This commit is contained in:
parent
317e3a2049
commit
a528a36068
@ -3,7 +3,7 @@ package cfg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -86,8 +86,7 @@ type Authorization struct {
|
|||||||
|
|
||||||
// ReadConfigFile reads a config on the given path and stores the
|
// ReadConfigFile reads a config on the given path and stores the
|
||||||
// configuration. Call it sometime during the initialization.
|
// configuration. Call it sometime during the initialization.
|
||||||
// Note that it may call log.Fatal, which terminates the program.
|
func ReadConfigFile(path string) error {
|
||||||
func ReadConfigFile(path string) {
|
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
WikiName: "Mycorrhiza Wiki",
|
WikiName: "Mycorrhiza Wiki",
|
||||||
NaviTitleIcon: "🍄",
|
NaviTitleIcon: "🍄",
|
||||||
@ -121,7 +120,7 @@ func ReadConfigFile(path string) {
|
|||||||
f = ini.Empty()
|
f = ini.Empty()
|
||||||
dirty = true
|
dirty = true
|
||||||
} else {
|
} else {
|
||||||
log.Fatal("Failed to parse the config file:", err)
|
return fmt.Errorf("Failed to open the config file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,11 +133,10 @@ func ReadConfigFile(path string) {
|
|||||||
if HTTPPort != "" && HTTPPort != strconv.FormatUint(cfg.Network.HTTPPort, 10) {
|
if HTTPPort != "" && HTTPPort != strconv.FormatUint(cfg.Network.HTTPPort, 10) {
|
||||||
port, err := strconv.ParseUint(HTTPPort, 10, 64)
|
port, err := strconv.ParseUint(HTTPPort, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to parse the port from command-line arguments:", err)
|
return fmt.Errorf("Failed to parse the port from command-line arguments: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Network.HTTPPort = port
|
cfg.Network.HTTPPort = port
|
||||||
|
|
||||||
dirty = true
|
dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,14 +144,14 @@ func ReadConfigFile(path string) {
|
|||||||
if dirty {
|
if dirty {
|
||||||
err = f.ReflectFrom(cfg)
|
err = f.ReflectFrom(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to serialize the config:", err)
|
return fmt.Errorf("Failed to serialize the config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable key-value auto-aligning, but retain spaces around '=' sign
|
// Disable key-value auto-aligning, but retain spaces around '=' sign
|
||||||
ini.PrettyFormat = false
|
ini.PrettyFormat = false
|
||||||
ini.PrettyEqual = true
|
ini.PrettyEqual = true
|
||||||
if err = f.SaveTo(path); err != nil {
|
if err = f.SaveTo(path); err != nil {
|
||||||
log.Println("Failed to save the config file:", err)
|
return fmt.Errorf("Failed to save the config file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,4 +175,6 @@ func ReadConfigFile(path string) {
|
|||||||
if URL == "" {
|
if URL == "" {
|
||||||
URL = "http://0.0.0.0:" + HTTPPort
|
URL = "http://0.0.0.0:" + HTTPPort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
5
main.go
5
main.go
@ -25,7 +25,10 @@ func main() {
|
|||||||
if err := files.PrepareWikiRoot(); err != nil {
|
if err := files.PrepareWikiRoot(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
cfg.ReadConfigFile(files.ConfigPath())
|
|
||||||
|
if err := cfg.ReadConfigFile(files.ConfigPath()); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("Running Mycorrhiza Wiki 1.2.0 indev")
|
log.Println("Running Mycorrhiza Wiki 1.2.0 indev")
|
||||||
if err := os.Chdir(files.HyphaeDir()); err != nil {
|
if err := os.Chdir(files.HyphaeDir()); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user