From a830b93bc72e1f3c0e76fadc4a4a5921b657a265 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Thu, 23 Aug 2018 12:06:47 +0000 Subject: [PATCH] upd(all): new config options --- crm/flags.go | 9 ++++++++- crm/start.go | 17 ++++++++++++++++- sam/flags.go | 13 ++++++++++--- sam/start.go | 17 ++++++++++++++++- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/crm/flags.go b/crm/flags.go index 9ee4734cc..3bcf884de 100644 --- a/crm/flags.go +++ b/crm/flags.go @@ -10,9 +10,12 @@ type ( http struct { addr string logging bool + pretty bool + tracing bool } db struct { - dsn string + dsn string + profiler string } } ) @@ -47,5 +50,9 @@ func Flags(prefix ...string) { flag.StringVar(&config.http.addr, p("http-addr"), ":3000", "Listen address for HTTP server") flag.BoolVar(&config.http.logging, p("http-log"), true, "Enable/disable HTTP request log") + flag.BoolVar(&config.http.pretty, p("http-pretty-json"), false, "Prettify returned JSON output") + flag.BoolVar(&config.http.tracing, p("http-error-tracing"), false, "Return error stack frame") + flag.StringVar(&config.db.dsn, p("db-dsn"), "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection") + flag.StringVar(&config.db.profiler, p("db-profiler"), "", "Profiler for DB queries (none, stdout)") } diff --git a/crm/start.go b/crm/start.go index 3761058a5..828e747b1 100644 --- a/crm/start.go +++ b/crm/start.go @@ -14,6 +14,7 @@ import ( "github.com/crusttech/crust/crm/rest" "github.com/titpetric/factory" + "github.com/titpetric/factory/resputil" ) func Init() error { @@ -28,7 +29,21 @@ func Init() error { if err != nil { return err } - db.Profiler = &factory.Database.ProfilerStdout + switch config.db.profiler { + case "stdout": + db.Profiler = &factory.Database.ProfilerStdout + // @todo: profiling as an external service? + } + + // configure resputil options + resputil.SetConfig(resputil.Options{ + Pretty: config.http.pretty, + Trace: config.http.tracing, + Logger: func(err error) { + // @todo: error logging + }, + }) + return nil } diff --git a/sam/flags.go b/sam/flags.go index 4a52f66c9..be028d559 100644 --- a/sam/flags.go +++ b/sam/flags.go @@ -12,11 +12,14 @@ type ( http struct { addr string logging bool + pretty bool + tracing bool + } + db struct { + dsn string + profiler string } websocket websocket.Configuration - db struct { - dsn string - } } ) @@ -54,5 +57,9 @@ func Flags(prefix ...string) { flag.StringVar(&config.http.addr, p("http-addr"), ":3000", "Listen address for HTTP server") flag.BoolVar(&config.http.logging, p("http-log"), true, "Enable/disable HTTP request log") + flag.BoolVar(&config.http.pretty, p("http-pretty-json"), false, "Prettify returned JSON output") + flag.BoolVar(&config.http.tracing, p("http-error-tracing"), false, "Return error stack frame") + flag.StringVar(&config.db.dsn, p("db-dsn"), "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection") + flag.StringVar(&config.db.profiler, p("db-profiler"), "", "Profiler for DB queries (none, stdout)") } diff --git a/sam/start.go b/sam/start.go index 4179a3d0b..fc9a59845 100644 --- a/sam/start.go +++ b/sam/start.go @@ -15,6 +15,7 @@ import ( "github.com/crusttech/crust/sam/websocket" "github.com/titpetric/factory" + "github.com/titpetric/factory/resputil" ) func Init() error { @@ -29,7 +30,21 @@ func Init() error { if err != nil { return err } - db.Profiler = &factory.Database.ProfilerStdout + switch config.db.profiler { + case "stdout": + db.Profiler = &factory.Database.ProfilerStdout + // @todo: profiling as an external service? + } + + // configure resputil options + resputil.SetConfig(resputil.Options{ + Pretty: config.http.pretty, + Trace: config.http.tracing, + Logger: func(err error) { + // @todo: error logging + }, + }) + return nil }