feat: release v0.28 generic Go project scaffolding and lifecycle entry
This commit is contained in:
29
examples/program/internal/config/config.go
Normal file
29
examples/program/internal/config/config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user