From 4bcd6c411fc1718fcb2056bda25df6bf43b37000 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Sun, 24 Sep 2023 11:19:02 -0400 Subject: [PATCH] chore(refactor): move config to an internal package Signed-off-by: Chris Gianelloni --- config.go => internal/config/config.go | 2 +- main.go | 12 ++++++------ node.go | 10 ++++++---- utils.go | 4 +++- 4 files changed, 16 insertions(+), 12 deletions(-) rename config.go => internal/config/config.go (99%) diff --git a/config.go b/internal/config/config.go similarity index 99% rename from config.go rename to internal/config/config.go index c12aea7..6d1a0aa 100644 --- a/config.go +++ b/internal/config/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package config import ( "fmt" diff --git a/main.go b/main.go index 35e73fe..f2ced88 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ import ( "github.com/shirou/gopsutil/v3/process" terminal "golang.org/x/term" + "github.com/blinklabs-io/nview/internal/config" "github.com/blinklabs-io/nview/internal/version" ) @@ -80,7 +81,7 @@ func main() { flag.Parse() // Load config - cfg, err := LoadConfig(cmdlineFlags.configFile) + cfg, err := config.LoadConfig(cmdlineFlags.configFile) if err != nil { fmt.Printf("Failed to load config: %s", err) os.Exit(1) @@ -284,7 +285,7 @@ var uptimes uint64 var epochItemsLast = 0 func getTestText(ctx context.Context, promMetrics *PromMetrics) string { - cfg := GetConfig() + cfg := config.GetConfig() // Refresh process metrics from host processMetrics, err := getProcessMetrics(ctx) if err != nil { @@ -399,7 +400,7 @@ func getTestText(ctx context.Context, promMetrics *PromMetrics) string { } func getHomeText(ctx context.Context, promMetrics *PromMetrics) string { - cfg := GetConfig() + cfg := config.GetConfig() processMetrics, err := getProcessMetrics(ctx) if err != nil { uptimes = 0 @@ -916,9 +917,8 @@ var checkPeers bool = false var pingPeers bool = false var showPeers bool = false -//nolint:unused func getPeerText(ctx context.Context) string { - cfg := GetConfig() + cfg := config.GetConfig() // Refresh metrics from host processMetrics, err := getProcessMetrics(ctx) if err != nil { @@ -1334,7 +1334,7 @@ type Peer struct { } func getProcessMetrics(ctx context.Context) (*process.Process, error) { - cfg := GetConfig() + cfg := config.GetConfig() r, _ := process.NewProcessWithContext(ctx, 0) processes, err := process.ProcessesWithContext(ctx) if err != nil { diff --git a/node.go b/node.go index bdb7410..21a2f76 100644 --- a/node.go +++ b/node.go @@ -22,6 +22,8 @@ import ( ouroboros "github.com/blinklabs-io/gouroboros" "github.com/blinklabs-io/gouroboros/protocol/chainsync" "github.com/blinklabs-io/gouroboros/protocol/localstatequery" + + "github.com/blinklabs-io/nview/internal/config" ) func buildLocalStateQueryConfig() localstatequery.Config { @@ -33,7 +35,7 @@ func buildChainSyncConfig() chainsync.Config { return chainsync.NewConfig() } -func createClientConnection(cfg *Config) net.Conn { +func createClientConnection(cfg *config.Config) net.Conn { var err error var conn net.Conn var dialProto string @@ -54,7 +56,7 @@ func createClientConnection(cfg *Config) net.Conn { } // Get Genesis Config from a running node using Ouroboros NtC -func getGenesisConfig(cfg *Config) *localstatequery.GenesisConfigResult { +func getGenesisConfig(cfg *config.Config) *localstatequery.GenesisConfigResult { var result *localstatequery.GenesisConfigResult // Get a connection and setup our error channels conn := createClientConnection(cfg) @@ -93,7 +95,7 @@ func getGenesisConfig(cfg *Config) *localstatequery.GenesisConfigResult { // Get Protocol Parameters from a running node using Ouroboros NtC // //nolint:unused -func getProtocolParams(cfg *Config) *localstatequery.CurrentProtocolParamsResult { +func getProtocolParams(cfg *config.Config) *localstatequery.CurrentProtocolParamsResult { var result *localstatequery.CurrentProtocolParamsResult // Get a connection and setup our error channels conn := createClientConnection(cfg) @@ -132,7 +134,7 @@ func getProtocolParams(cfg *Config) *localstatequery.CurrentProtocolParamsResult // Get remote tip // //nolint:unused -func getRemoteTip(cfg *Config, address string) *chainsync.Tip { +func getRemoteTip(cfg *config.Config, address string) *chainsync.Tip { var result *chainsync.Tip // Get a connection and setup our error channels conn := createRemoteClientConnection(address) diff --git a/utils.go b/utils.go index a23365d..72389e5 100644 --- a/utils.go +++ b/utils.go @@ -20,10 +20,12 @@ import ( "os/exec" "strings" "time" + + "github.com/blinklabs-io/nview/internal/config" ) func getNodeVersion() (version string, revision string, err error) { - cfg := GetConfig() + cfg := config.GetConfig() cmd := exec.Command(cfg.Node.Binary, "version") stdout, err := cmd.Output() if err != nil {