Skip to content

Commit

Permalink
ReadYamlConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo committed Dec 30, 2024
1 parent 1d8d591 commit 0a07994
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
50 changes: 50 additions & 0 deletions common/read_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package common

import (
"encoding/json"
"errors"
"log"
"os"
"path/filepath"

"gopkg.in/yaml.v3"
)

func ReadYamlConfig(path string, o interface{}) error {
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
log.Fatal("Path ", path, " does not exist")
}
b, err := ReadFile(path)
if err != nil {
return err
}

err = yaml.Unmarshal(b, o)
if err != nil {
log.Fatalf("unable to parse file with error %#v", err)
}

return nil
}

func ReadFile(path string) ([]byte, error) {
b, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return nil, err
}
return b, nil
}

func ReadJsonConfig(path string, o interface{}) error {
b, err := ReadFile(path)
if err != nil {
return err
}

err = json.Unmarshal(b, o)
if err != nil {
log.Fatalf("unable to parse file with error %#v", err)
}

return nil
}
3 changes: 2 additions & 1 deletion core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/signerv2"
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
"github.com/ethereum/go-ethereum/ethclient"

sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
Expand Down Expand Up @@ -69,7 +70,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
var configRaw ConfigRaw
configFilePath := ctx.GlobalString(ConfigFileFlag.Name)
if configFilePath != "" {
sdkutils.ReadYamlConfig(configFilePath, &configRaw)
commonincredible.ReadYamlConfig(configFilePath, &configRaw)
}

var credibleSquaringDeploymentRaw IncredibleSquaringDeploymentRaw
Expand Down

0 comments on commit 0a07994

Please sign in to comment.