summaryrefslogtreecommitdiff
path: root/cmd/rr/utils/config.go
blob: 452dd195c9b3788e11533f19b2d025ee1faa03ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package utils

import (
	"github.com/spf13/viper"
	"github.com/spiral/roadrunner/service"
)

// ViperWrapper provides interface bridge between Viper configs and service.Config.
type ViperWrapper struct {
	Viper *viper.Viper
}

// Get nested config section (sub-map), returns nil if section not found.
func (w *ViperWrapper) Get(key string) service.Config {
	sub := w.Viper.Sub(key)
	if sub == nil {
		return nil
	}

	return &ViperWrapper{sub}
}

// Unmarshal unmarshal config data into given struct.
func (w *ViperWrapper) Unmarshal(out interface{}) error {
	return w.Viper.Unmarshal(out)
}