From 408de1d2b299b7524d8153658b8d6d4d7564744c Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 27 Nov 2023 21:27:47 +0100 Subject: [PATCH] chore: add initialization function for Config struct --- cmd/blobstream/query/cmd.go | 48 +++++++++++++++++----------------- cmd/blobstream/query/config.go | 9 +++++++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/cmd/blobstream/query/cmd.go b/cmd/blobstream/query/cmd.go index b661fdbf..da31f748 100644 --- a/cmd/blobstream/query/cmd.go +++ b/cmd/blobstream/query/cmd.go @@ -519,24 +519,24 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er orchConf, err := orchestrator.GetStartConfig(v, configPath) if err == nil { // it is an orchestrator, so we get the config from it - return Config{ - coreGRPC: orchConf.CoreGRPC, - coreRPC: orchConf.CoreRPC, - targetNode: orchConf.Bootstrappers, - grpcInsecure: orchConf.GRPCInsecure, - }, nil + return *NewPartialConfig( + orchConf.CoreGRPC, + orchConf.CoreRPC, + orchConf.Bootstrappers, + orchConf.GRPCInsecure, + ), nil } // assume this home is a relayer home directory relConf, err := relayer.GetStartConfig(v, configPath) if err == nil { // it is a relayer, so we get the config from it - return Config{ - coreGRPC: relConf.CoreGRPC, - coreRPC: relConf.CoreRPC, - targetNode: relConf.Bootstrappers, - grpcInsecure: relConf.GrpcInsecure, - }, nil + return *NewPartialConfig( + relConf.CoreGRPC, + relConf.CoreRPC, + relConf.Bootstrappers, + relConf.GrpcInsecure, + ), nil } return Config{}, fmt.Errorf("the provided home directory is neither an orchestrator nor a relayer home directory") } @@ -549,12 +549,12 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er if err == nil { // found orchestrator home, get the config from it logger.Debug("using home", "home", orchHome) - return Config{ - coreGRPC: orchConf.CoreGRPC, - coreRPC: orchConf.CoreRPC, - targetNode: orchConf.Bootstrappers, - grpcInsecure: orchConf.GRPCInsecure, - }, nil + return *NewPartialConfig( + orchConf.CoreGRPC, + orchConf.CoreRPC, + orchConf.Bootstrappers, + orchConf.GRPCInsecure, + ), nil } // try to get the config from the relayer home directory @@ -566,12 +566,12 @@ func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, er if err == nil { // found relayer home, so we get the config from it logger.Debug("using home", "home", relHome) - return Config{ - coreGRPC: relConf.CoreGRPC, - coreRPC: relConf.CoreRPC, - targetNode: relConf.Bootstrappers, - grpcInsecure: relConf.GrpcInsecure, - }, nil + return *NewPartialConfig( + relConf.CoreGRPC, + relConf.CoreRPC, + relConf.Bootstrappers, + relConf.GrpcInsecure, + ), nil } return *DefaultConfig(), nil diff --git a/cmd/blobstream/query/config.go b/cmd/blobstream/query/config.go index ee0dbf52..4373ef69 100644 --- a/cmd/blobstream/query/config.go +++ b/cmd/blobstream/query/config.go @@ -31,6 +31,15 @@ type Config struct { grpcInsecure bool } +func NewPartialConfig(coreGRPC, coreRPC, targetNode string, grpcInsecure bool) *Config { + return &Config{ + coreGRPC: coreGRPC, + coreRPC: coreRPC, + targetNode: targetNode, + grpcInsecure: grpcInsecure, + } +} + func DefaultConfig() *Config { return &Config{ coreGRPC: "localhost:9090",