cmd: convert from fmt to log package
This commit is contained in:
parent
65e43df8d2
commit
adbe71525a
@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
@ -27,34 +27,30 @@ func main() {
|
||||
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())
|
||||
log.Printf("Failed to save default configuration file: %s", err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Failed to load configuration file '%s': %s\n", *configPath, err.Error())
|
||||
os.Exit(1)
|
||||
log.Fatalf("Failed to load configuration file '%s': %s\n", *configPath, err.Error())
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Loading configuration from '%s'...\n", *configPath)
|
||||
log.Printf("Loading configuration from '%s'...\n", *configPath)
|
||||
err = json.Unmarshal(cfg, &opts)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to parse configuration file: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
log.Fatalf("Failed to parse configuration file: %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
ws, err := yatwiki.NewWikiServer(&opts)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
fmt.Printf("YATWiki now listening on %s\n", *bindAddr)
|
||||
log.Printf("YATWiki now listening on %s\n", *bindAddr)
|
||||
err = http.ListenAndServe(*bindAddr, ws)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
|
Loading…
Reference in New Issue
Block a user