func getConfig() (*Config, error) {
	var config Config
	if err := viper.ReadInConfig(); err != nil {
		return nil, errors.Wrap(err, "getConfig(ReadInConfig)")
	}
	if err := viper.Unmarshal(&config); err != nil {
		return nil, errors.Wrap(err, "getConfig(Unmarshal)")
	}
	return &config, nil
}
read and unmarshal configfile into Config struct
package cmd
import (
	"fmt"
	"os"
	"strings"
	homedir "github.com/mitchellh/go-homedir"
	"github.com/pkg/errors"
	"github.com/sap/gorfc/gorfc"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)
type serverInfo struct {
	name string
	conn *gorfc.Connection
}
type SystemInfo struct {
	Name   string
	Usage  string
	Tags   []string
	User   string
	Lang   string
	Client string
	Server string
	Sysnr  string
	Mshost string
	Msserv string
	Group  string
	Saprouter string
}
type tomlMetric struct {
	Name           string
	Help           string
	MetricType     string
	TagFilter      []string
	AllServers     bool
	FunctionModule string
	Params         map[string]interface{}
	TableData      TableInfo
	FieldData      FieldInfo
	StructureData  StructureInfo
}
type TableInfo struct {
	Table     string
	RowCount  map[string][]interface{}
	RowFilter map[string][]interface{}
}
type FieldInfo struct {
	FieldLabels []string
	FieldValues []string
}
type StructureInfo struct {
	ExportStructure string
	StructureFields []string
}
type metricInfo struct {
	Name           string
	Help           string
	MetricType     string
	TagFilter      []string
	AllServers     bool
	FunctionModule string
	Params         map[string]interface{}
	special        dataReceiver
}
type dataReceiver interface {
	checkSpecialData() bool
	metricData(rawData map[string]interface{}, system SystemInfo, srvName string) []metricRecord
}
type Config struct {
	Secret     []byte
	Systems    []SystemInfo  
	Metrics    []tomlMetric  
	IntMetrics []metricInfo  
	passwords  map[string]string
	Timeout    uint
	port       string
}
var cfgFile string
var rootCmd = &cobra.Command{
	Use:   "sapnwrfc_exporter",
	Short: "The purpose of this sapnwrfc_exporter is to support monitoring SAP ABAP instances with Prometheus and Grafana.",
	Long:  `The purpose of the sapnwrfc_exporter is to support monitoring SAP ABAP instances with Prometheus and Grafana. It is possible to count the occurrence for some defined values of a field in a SAP function module result table - for example the number of dialog, batch and update processes or the number of the SAP lock entries at a given time. Another possibility is to use the export field results of a function module as prometheus label values - for example to record the database client version and kernel patch level of the SAP instance. Also values of sap rfc function module result structures or fields can be monitored`,
}
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		exit("RootCmd can't be executed: ", err)
	}
}
func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.hana_sql_exporter.toml)")
}
func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		home, err := homedir.Dir()
		if err != nil {
			exit("Homedir can't be found: ", err)
		}
		viper.AddConfigPath(home)
		viper.SetConfigType("toml")
		viper.SetConfigName(".sapnwrfc_exporter.toml")
	}
}