mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-29 21:27:05 +02:00
Use config.ServiceConfig across API
This commit is contained in:
parent
091b3c2f49
commit
9c363cc06d
27 changed files with 137 additions and 99 deletions
|
@ -18,6 +18,7 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -30,11 +31,11 @@ type ServiceConfig struct {
|
|||
func NewServiceConfig(name string, config *viper.Viper) ServiceConfig {
|
||||
service := ServiceConfig{
|
||||
Name: name,
|
||||
Backend: viper.GetString("backend"),
|
||||
Backend: config.GetString("backend"),
|
||||
ConfigValues: make(map[string]any),
|
||||
}
|
||||
|
||||
for key, val := range viper.AllSettings() {
|
||||
for key, val := range config.AllSettings() {
|
||||
if key != "backend" {
|
||||
service.ConfigValues[key] = val
|
||||
}
|
||||
|
@ -43,6 +44,19 @@ func NewServiceConfig(name string, config *viper.Viper) ServiceConfig {
|
|||
return service
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) GetString(key string) string {
|
||||
return cast.ToString(c.ConfigValues[key])
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) GetBool(key string) bool {
|
||||
return cast.ToBool(c.ConfigValues[key])
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) IsSet(key string) bool {
|
||||
_, ok := c.ConfigValues[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) Save() error {
|
||||
key := "service." + c.Name
|
||||
viper.Set(key+".backend", c.Backend)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue