github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/jsp/app.go (about)

     1  // Package jsp (JSON persistence) provides utilities to store and load arbitrary
     2  // JSON-encoded structures with optional checksumming and compression.
     3  /*
     4   * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package jsp
     7  
     8  import (
     9  	"fmt"
    10  	"path/filepath"
    11  
    12  	"github.com/NVIDIA/aistore/cmn/cos"
    13  )
    14  
    15  func LoadAppConfig(configDir, configFname string, v any) (err error) {
    16  	path := filepath.Join(configDir, configFname)
    17  	if err = cos.Stat(path); err != nil {
    18  		return err
    19  	}
    20  	if _, err = Load(path, v, Options{Indent: true}); err != nil {
    21  		err = fmt.Errorf("failed to load config file %q: %v", path, err)
    22  	}
    23  	return
    24  }
    25  
    26  func SaveAppConfig(configDir, configFname string, v any) error {
    27  	path := filepath.Join(configDir, configFname)
    28  	return Save(path, v, Options{Indent: true}, nil /*sgl*/)
    29  }