2016-05-30 16:08:09 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import "github.com/imdario/mergo"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// TimeFormat default time format for any kind of datetime parsing
|
|
|
|
TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2016-06-03 04:11:50 +02:00
|
|
|
// Logger contains the configs for the Logger
|
2016-05-30 16:08:09 +02:00
|
|
|
Logger struct {
|
|
|
|
Out io.Writer
|
|
|
|
Prefix string
|
|
|
|
Flag int
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-06-03 04:11:50 +02:00
|
|
|
// DefaultLogger returns the default configs for the Logger
|
2016-05-30 16:08:09 +02:00
|
|
|
func DefaultLogger() Logger {
|
|
|
|
return Logger{Out: os.Stdout, Prefix: "", Flag: 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge merges the default with the given config and returns the result
|
|
|
|
func (c Logger) Merge(cfg []Logger) (config Logger) {
|
|
|
|
|
|
|
|
if len(cfg) > 0 {
|
|
|
|
config = cfg[0]
|
|
|
|
mergo.Merge(&config, c)
|
|
|
|
} else {
|
|
|
|
_default := c
|
|
|
|
config = _default
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-06-01 14:29:38 +02:00
|
|
|
// MergeSingle merges the default with the given config and returns the result
|
2016-05-30 16:08:09 +02:00
|
|
|
func (c Logger) MergeSingle(cfg Logger) (config Logger) {
|
|
|
|
|
|
|
|
config = cfg
|
|
|
|
mergo.Merge(&config, c)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|