-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
36 lines (31 loc) · 823 Bytes
/
Copy pathconfig.go
File metadata and controls
36 lines (31 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"encoding/json"
"fmt"
"os"
)
type NetworkConfig struct {
ID string `json:"id"`
IndexerURL string `json:"indexer"`
RPCURL string `json:"rpc,omitempty"`
}
type AppConfig struct {
Networks []NetworkConfig `json:"networks"`
}
var defaultConfig = &AppConfig{
Networks: []NetworkConfig{
{ID: "gnoland1", IndexerURL: "https://indexer.gno.land/graphql/query", RPCURL: "https://rpc.gno.land"},
{ID: "test12", IndexerURL: "https://indexer.test12.moul.p2p.team/graphql"},
},
}
func LoadConfig(path string) (*AppConfig, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read config %s: %w", path, err)
}
var cfg AppConfig
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config: %w", err)
}
return &cfg, nil
}