blob: 83a6bdf208d217fb2a31cb4586ad460a1e68b5bd [file] [log] [blame]
package features
import (
"encoding/json"
"errors"
"os"
log "github.com/golang/glog"
)
// GPUConfig represents the structure of the cos-gpu-config file.
type GPUConfig struct {
UseProto bool `json:"use-proto"`
}
// ReadCOSGPUConfig will read the cos-gpu-config.json file at the given path and parse the data to the GPUConfig instance.
// If the cos-gpu-config.json file doesn't exist, it will return a default GPUConfig instance.
func ReadCOSGPUConfig(path string) (*GPUConfig, error) {
defaultGPUConfig := &GPUConfig{
UseProto: false,
}
configContent, err := os.ReadFile(path)
if err != nil {
// If the file does not exist, return the default config without error.
if errors.Is(err, os.ErrNotExist) {
log.Infof("COS GPU config file does not exist, default GPU config: %+v will be used.", defaultGPUConfig)
return defaultGPUConfig, nil
}
return nil, err
}
var gpuConfig GPUConfig
err = json.Unmarshal(configContent, &gpuConfig)
if err != nil {
return nil, err
}
return &gpuConfig, nil
}