56 lines
1.4 KiB
Go
Raw Normal View History

2024-10-18 04:28:31 +00:00
package app
import (
"encoding/json"
"log"
"os"
"strings"
2024-10-18 04:28:31 +00:00
)
2024-12-27 19:59:44 +00:00
const MiB = 1024 * 1024
2024-10-18 04:28:31 +00:00
type Config struct {
ListenPort int `json:"listenPort"`
PVE struct {
URL string `json:"url"`
2024-10-18 04:28:31 +00:00
Token struct {
2024-12-27 19:59:44 +00:00
USER string `json:"user"`
REALM string `json:"realm"`
2024-10-18 04:28:31 +00:00
ID string `json:"id"`
2024-12-27 19:59:44 +00:00
Secret string `json:"uuid"`
2024-10-18 04:28:31 +00:00
}
}
ReloadInterval int `json:"rebuildInterval"`
2024-10-18 04:28:31 +00:00
}
func GetConfig(configPath string) Config {
content, err := os.ReadFile(configPath)
if err != nil {
log.Fatal("Error when opening config file: ", err)
}
var config Config
err = json.Unmarshal(content, &config)
if err != nil {
log.Fatal("Error during parsing config file: ", err)
}
return config
}
2024-12-27 19:59:44 +00:00
// returns if a device pcie bus id is a super device or subsystem device
//
// subsystem devices always has the format xxxx:yy.z, whereas super devices have the format xxxx:yy
//
// returns true if BusID has format xxxx:yy
func DeviceBusIDIsSuperDevice(BusID string) bool {
return !strings.ContainsRune(BusID, '.')
}
// returns if a device pcie bus id is a subdevice of specified super device
//
// subsystem devices always has the format xxxx:yy.z, whereas super devices have the format xxxx:yy
//
// returns true if BusID has prefix SuperDeviceBusID and SuperDeviceBusID is a Super Device
func DeviceBusIDIsSubDevice(BusID string, SuperDeviceBusID string) bool {
return DeviceBusIDIsSuperDevice(SuperDeviceBusID) && strings.HasPrefix(BusID, SuperDeviceBusID)
2024-12-27 19:59:44 +00:00
}