use log.Fatal instead panic on config errors

This commit is contained in:
dhax 2017-10-19 00:40:25 +02:00
parent 2dc0f02d1c
commit fce1b99683
7 changed files with 22 additions and 28 deletions

View file

@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"log"
"github.com/dhax/go-base/api"
"github.com/go-chi/docgen"
@ -67,8 +68,8 @@ func genRoutesDoc() {
Intro: "GoBase REST API.",
})
if err := ioutil.WriteFile("routes.md", []byte(md), 0644); err != nil {
fmt.Print(err)
log.Println(err)
return
}
fmt.Print("OK\n")
fmt.Println("OK")
}

View file

@ -16,6 +16,7 @@ package cmd
import (
"fmt"
"log"
"os"
homedir "github.com/mitchellh/go-homedir"
@ -76,8 +77,7 @@ func initConfig() {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
log.Fatal(err)
}
// Search config in home directory with name ".go-base" (without extension).

View file

@ -15,6 +15,8 @@
package cmd
import (
"log"
"github.com/dhax/go-base/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -28,7 +30,7 @@ var serveCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
server, err := api.NewServer()
if err != nil {
panic(err)
log.Fatal(err)
}
server.Start()
},