cmd: convert from fmt to log package

This commit is contained in:
mappu 2018-04-02 16:51:08 +12:00
parent 65e43df8d2
commit adbe71525a

View File

@ -3,8 +3,8 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"os" "os"
@ -27,34 +27,30 @@ func main() {
if cfg, err := json.MarshalIndent(opts, "", "\t"); err == nil { if cfg, err := json.MarshalIndent(opts, "", "\t"); err == nil {
err := ioutil.WriteFile(*configPath, cfg, 0644) err := ioutil.WriteFile(*configPath, cfg, 0644)
if err != nil { 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 { } else {
fmt.Fprintf(os.Stderr, "Failed to load configuration file '%s': %s\n", *configPath, err.Error()) log.Fatalf("Failed to load configuration file '%s': %s\n", *configPath, err.Error())
os.Exit(1)
} }
} else { } else {
fmt.Printf("Loading configuration from '%s'...\n", *configPath) log.Printf("Loading configuration from '%s'...\n", *configPath)
err = json.Unmarshal(cfg, &opts) err = json.Unmarshal(cfg, &opts)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse configuration file: %s\n", err.Error()) log.Fatalf("Failed to parse configuration file: %s\n", err.Error())
os.Exit(1)
} }
} }
ws, err := yatwiki.NewWikiServer(&opts) ws, err := yatwiki.NewWikiServer(&opts)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) log.Fatalln(err.Error())
os.Exit(1)
} }
defer ws.Close() 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) err = http.ListenAndServe(*bindAddr, ws)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) log.Fatalln(err.Error())
os.Exit(1)
} }
os.Exit(0) os.Exit(0)