Refactor config error message

This commit is contained in:
Kailash Nadh 2019-07-12 17:19:26 +05:30
parent 3d3af8c429
commit 275554e57e
3 changed files with 9 additions and 6 deletions

View File

@ -2,7 +2,7 @@
- Run `./listmonk --new-config` to generate a sample `config.toml` and add your configuration (SMTP and Postgres DB credentials primarily). - Run `./listmonk --new-config` to generate a sample `config.toml` and add your configuration (SMTP and Postgres DB credentials primarily).
- `./listmonk --install` to setup the DB. - `./listmonk --install` to setup the DB.
- Visit `http://localhost:9000`. - Run `./listmonk` and visit `http://localhost:9000`.
## Running on Docker ## Running on Docker

View File

@ -11,7 +11,7 @@ listmonk is a standalone, self-hosted, newsletter and mailing list manager. It i
- Download the [latest release](https://github.com/knadh/listmonk/releases) and extract the listmonk binary somewhere. - Download the [latest release](https://github.com/knadh/listmonk/releases) and extract the listmonk binary somewhere.
- Run `./listmonk --new-config` to generate a sample `config.toml` and add your configuration (SMTP and Postgres DB credentials primarily). - Run `./listmonk --new-config` to generate a sample `config.toml` and add your configuration (SMTP and Postgres DB credentials primarily).
- `./listmonk --install` to setup the DB. - `./listmonk --install` to setup the DB.
- Visit `http://localhost:9000`. - Run `./listmonk` and visit `http://localhost:9000`.
- Since there is no user auth yet, it's best to put listmonk behind a proxy like Nginx and setup basicauth on all endpoints except for the few endpoints that need to be public. Here is a [sample nginx config](https://github.com/knadh/listmonk/wiki/Production-Nginx-config) for production use. - Since there is no user auth yet, it's best to put listmonk behind a proxy like Nginx and setup basicauth on all endpoints except for the few endpoints that need to be public. Here is a [sample nginx config](https://github.com/knadh/listmonk/wiki/Production-Nginx-config) for production use.
### Running on Docker ### Running on Docker

11
main.go
View File

@ -85,19 +85,22 @@ func init() {
// Generate new config. // Generate new config.
if ok, _ := f.GetBool("new-config"); ok { if ok, _ := f.GetBool("new-config"); ok {
if err := newConfigFile(); err != nil { if err := newConfigFile(); err != nil {
fmt.Println(err) logger.Println(err)
os.Exit(1) os.Exit(1)
} }
fmt.Println("generated config.toml. Edit and run --install") logger.Println("generated config.toml. Edit and run --install")
os.Exit(0) os.Exit(0)
} }
// Load config files. // Load config files.
cFiles, _ := f.GetStringSlice("config") cFiles, _ := f.GetStringSlice("config")
for _, f := range cFiles { for _, f := range cFiles {
log.Printf("reading config: %s", f) logger.Printf("reading config: %s", f)
if err := ko.Load(file.Provider(f), toml.Parser()); err != nil { if err := ko.Load(file.Provider(f), toml.Parser()); err != nil {
log.Fatalf("error loadng config: %v", err) if os.IsNotExist(err) {
logger.Fatal("config file not found. If there isn't one yet, run --new-config to generate one.")
}
logger.Fatalf("error loadng config: %v.", err)
} }
} }
ko.Load(posflag.Provider(f, ".", ko), nil) ko.Load(posflag.Provider(f, ".", ko), nil)