add(config): import global config pkg
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/namsral/flag"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
Database struct {
|
||||
DSN string
|
||||
Profiler string
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Database) Validate() error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
if c.DSN == "" {
|
||||
return errors.New("No DB DSN is set, can't connect to database")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Database) Init(prefix ...string) *Database {
|
||||
p := func(s string) string {
|
||||
return prefix[0] + "-" + s
|
||||
}
|
||||
|
||||
flag.StringVar(&c.DSN, p("db-dsn"), "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.StringVar(&c.Profiler, p("db-profiler"), "", "Profiler for DB queries (none, stdout)")
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/namsral/flag"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
HTTP struct {
|
||||
Addr string
|
||||
Logging bool
|
||||
Pretty bool
|
||||
Tracing bool
|
||||
Metrics bool
|
||||
}
|
||||
)
|
||||
|
||||
func (c *HTTP) Validate() error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
if c.Addr == "" {
|
||||
return errors.New("No HTTP Addr is set, can't listen for HTTP")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *HTTP) Init(prefix ...string) *HTTP {
|
||||
p := func(s string) string {
|
||||
return prefix[0] + "-" + s
|
||||
}
|
||||
|
||||
flag.StringVar(&c.Addr, p("http-addr"), ":3000", "Listen address for HTTP server")
|
||||
flag.BoolVar(&c.Logging, p("http-log"), true, "Enable/disable HTTP request log")
|
||||
flag.BoolVar(&c.Pretty, p("http-pretty-json"), false, "Prettify returned JSON output")
|
||||
flag.BoolVar(&c.Tracing, p("http-error-tracing"), false, "Return error stack frame")
|
||||
flag.BoolVar(&c.Metrics, p("http-metrics"), false, "Provide metrics export for prometheus")
|
||||
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/namsral/flag"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
JWT struct {
|
||||
Secret string
|
||||
Expiry int64
|
||||
DebugToken bool
|
||||
}
|
||||
)
|
||||
|
||||
func (c *JWT) Validate() error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
if c.Secret == "" {
|
||||
return errors.New("JWT Secret not set for AUTH")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *JWT) Init(prefix ...string) *JWT {
|
||||
flag.StringVar(&c.Secret, "auth-jwt-secret", "", "JWT Secret")
|
||||
flag.Int64Var(&c.Expiry, "auth-jwt-expiry", 3600, "JWT Expiration in minutes")
|
||||
flag.BoolVar(&c.DebugToken, "auth-jwt-debug", false, "Generate debug JWT key")
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user