upd(all): new config options

This commit is contained in:
Tit Petric
2018-08-23 12:06:47 +00:00
parent 5e76b12901
commit a830b93bc7
4 changed files with 50 additions and 6 deletions
+8 -1
View File
@@ -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)")
}
+16 -1
View File
@@ -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
}
+10 -3
View File
@@ -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)")
}
+16 -1
View File
@@ -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
}