spf13/viper не может прочитать файл

По аналогии с https://github.com/gogjango/gjango/blob/master/config/config.go

package config

import (
    "fmt"
    "log"
    "os"
    "path/filepath"
    "read-clickhouse/tools"
    "runtime"

    "github.com/gin-gonic/gin"
    "github.com/spf13/viper"
)

func check() {
    _, filePath, _, _ := runtime.Caller(0)
    configName := "config.dev.yaml"
    configPath := filePath[:len(filePath)-9] + "files" + string(filepath.Separator)

    filename := fmt.Sprintf("%s%s", configPath, configName)

    if _, err := os.Stat(filename); err == nil {
        fmt.Println("Файл существует")
    } else if os.IsNotExist(err) {
        fmt.Println("Файл не существует")
    } else {
        fmt.Println("Ошибка при проверке файла:", err)
    }
}

// Load returns Configuration struct
func Load(env string) *Configuration {
    check()
    _, filePath, _, _ := runtime.Caller(0)
    configName := "config." + env + ".yaml"
    configPath := filePath[:len(filePath)-9] + "files" + string(filepath.Separator)

    tools.DebugPrintf(configName)
    viper.SetConfigName(configName)
    viper.AddConfigPath(configPath)

    err := viper.ReadInConfig()
    if err != nil {
        log.Fatal(err)
    }

    var config Configuration
    viper.Unmarshal(&config)
    setGinMode(config.Server.Mode)

    return &config
}

// Configuration holds data necessery for configuring application
type Configuration struct {
    Server *Server `yaml:"server"`
}

// Server holds data necessary for server configuration
type Server struct {
    Mode string `yaml:"mode"`
}

func setGinMode(mode string) {
    switch mode {
    case "release":
        gin.SetMode(gin.ReleaseMode)
        break
    case "test":
        gin.SetMode(gin.TestMode)
        break
    default:
        gin.SetMode(gin.DebugMode)
    }
}

вывод

    go run main.go
    Файл существует
    [/home/des/proj/go-read-clickhouse/config/config.go:read-clickhouse/config.Load 38] 
    %!(EXTRA string=config.dev.yaml)

    2024/02/02 16:34:51 Config File "config.dev.yaml" Not Found in "[/home/des/proj/go-read-clickhouse/config/files]"
    exit status 1
    make: *** [Makefile:2: run] Ошибка 1

сам файл в папке есть. ось - убунта. права 0775 накинул


Ответы (1 шт):

Автор решения: des1roer

не хватало


    viper.SetConfigType("yaml")
→ Ссылка