switch configuration from xml to json

This commit is contained in:
mappu 2017-07-11 19:34:49 +12:00
parent 3764caacc8
commit f465c823f3
2 changed files with 5 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ cmd/yatwiki-server/yatwiki-server
# Development db files
cmd/yatwiki-server/wiki.db
cmd/yatwiki-server/config.json

View File

@ -1,7 +1,7 @@
package main
import (
"encoding/xml"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
@ -14,7 +14,7 @@ import (
func main() {
bindAddr := flag.String("listen", "127.0.0.1:80", "Bind address")
configPath := flag.String("config", "config.xml", "Configuration file")
configPath := flag.String("config", "config.json", "Configuration file")
flag.Parse()
opts := yatwiki3.ServerOptions{}
@ -24,7 +24,7 @@ func main() {
if err != nil {
if os.IsNotExist(err) {
opts = *yatwiki3.DefaultOptions()
if cfg, err := xml.MarshalIndent(opts, "", "\t"); err == nil {
if cfg, err := json.MarshalIndent(opts, "", "\t"); err == nil {
err := ioutil.WriteFile(*configPath, cfg, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to save default configuration file: %s", err.Error())
@ -36,7 +36,7 @@ func main() {
}
} else {
fmt.Printf("Loading configuration from '%s'...\n", *configPath)
err = xml.Unmarshal(cfg, &opts)
err = json.Unmarshal(cfg, &opts)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse configuration file: %s\n", err.Error())
os.Exit(1)