func initConfig(_ *appcontext.Context, v *viper.Viper, confPath, defaultPath string, resolveTo interface{}) error {
	if confPath != "" {
		v.SetConfigFile(confPath)
	} else {
		v.SetConfigFile(defaultPath)
	}
	v.AutomaticEnv()
	if err := v.ReadInConfig(); err != nil {
		return fmt.Errorf("%w: %v", errReadConfig, err)
	}
	if err := v.Unmarshal(resolveTo); err != nil {
		return fmt.Errorf("%w: %v", errUnmarshalConfig, err)
	}
	return nil
}
initConfig reads and unmarshals the config.
package cmd
import (
	"fmt"
	"os"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"github.com/sdslabs/pinger/pkg/util/appcontext"
)
var (
	errReadConfig      = fmt.Errorf("cannot read config file")
	errUnmarshalConfig = fmt.Errorf("cannot unmarshal config file")
	errBindFlags       = fmt.Errorf("cannot bind flags to viper")
)