1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pkg/config/load.go
Carlos Alexandro Becker c54e530902
refactor: moving config load logic to another file
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-02-19 20:49:39 -03:00

52 lines
1.1 KiB
Go

package config
import (
"fmt"
"io"
"os"
"github.com/goreleaser/goreleaser/internal/logext"
"github.com/goreleaser/goreleaser/internal/yaml"
)
// VersionError will happen if the goreleaser config file version does not
// match the current GoReleaser version.
type VersionError struct {
current int
}
func (e VersionError) Error() string {
return fmt.Sprintf(
"only configurations files on %s are supported, yours is %s, please update your configuration",
logext.Keyword("version: 1"),
logext.Keyword(fmt.Sprintf("version: %d", e.current)),
)
}
// Load config file.
func Load(file string) (config Project, err error) {
f, err := os.Open(file) // #nosec
if err != nil {
return
}
defer f.Close()
return LoadReader(f)
}
// LoadReader config via io.Reader.
func LoadReader(fd io.Reader) (config Project, err error) {
data, err := io.ReadAll(fd)
if err != nil {
return config, err
}
var versioned Versioned
_ = yaml.Unmarshal(data, &versioned)
if versioned.Version != 0 && versioned.Version != 1 {
return config, VersionError{versioned.Version}
}
err = yaml.UnmarshalStrict(data, &config)
return config, err
}