30 lines
813 B
Go
30 lines
813 B
Go
package config
|
|
|
|
import (
|
|
omniConfig "git.yuntuo.hk/k2safe/go-omni/config"
|
|
"git.yuntuo.hk/k2safe/go-omni/lifecycle"
|
|
"git.yuntuo.hk/k2safe/go-omni/logx"
|
|
)
|
|
|
|
// Config, Default and Validate are project-owned. Add project settings here.
|
|
type Config struct {
|
|
Once bool `json:"once"`
|
|
Log logx.Config `json:"log"`
|
|
Lifecycle lifecycle.ShutdownConfig `json:"lifecycle"`
|
|
}
|
|
|
|
func Default() Config {
|
|
log := logx.Default()
|
|
log.Service = "example.com/program"
|
|
return Config{Once: true, Log: log, Lifecycle: lifecycle.DefaultShutdownConfig()}
|
|
}
|
|
func (c Config) Validate() error {
|
|
if err := c.Log.Validate(); err != nil {
|
|
return omniConfig.AtField("log", err)
|
|
}
|
|
if err := c.Lifecycle.Validate(); err != nil {
|
|
return omniConfig.AtField("lifecycle", err)
|
|
}
|
|
return nil
|
|
}
|