1
0
out-of-tree/config/config.go

46 lines
844 B
Go
Raw Normal View History

2018-11-17 20:20:59 +00:00
// Copyright 2018 Mikhail Klementev. All rights reserved.
// Use of this source code is governed by a AGPLv3 license
// (or later) that can be found in the LICENSE file.
package config
import (
2024-02-20 13:25:31 +00:00
"io"
2018-11-17 20:20:59 +00:00
"os"
"code.dumpstack.io/tools/out-of-tree/distro"
2018-11-17 20:20:59 +00:00
"github.com/naoina/toml"
)
2019-08-17 08:51:42 +00:00
// KernelConfig is the ~/.out-of-tree/kernels.toml configuration description
2018-11-17 20:20:59 +00:00
type KernelConfig struct {
Kernels []distro.KernelInfo
2018-11-17 20:20:59 +00:00
}
func readFileAll(path string) (buf []byte, err error) {
f, err := os.Open(path)
if err != nil {
return
}
defer f.Close()
2024-02-20 13:25:31 +00:00
buf, err = io.ReadAll(f)
2018-11-17 20:20:59 +00:00
return
}
2019-08-17 08:51:42 +00:00
// ReadKernelConfig is for read kernels.toml
2018-11-17 20:20:59 +00:00
func ReadKernelConfig(path string) (kernelCfg KernelConfig, err error) {
buf, err := readFileAll(path)
if err != nil {
return
}
err = toml.Unmarshal(buf, &kernelCfg)
if err != nil {
return
}
return
}