diff --git a/cmd/thalos/antelope_api_helpers.go b/cmd/thalos/antelope_api_helpers.go new file mode 100644 index 0000000..0096143 --- /dev/null +++ b/cmd/thalos/antelope_api_helpers.go @@ -0,0 +1,35 @@ +package main + +import ( + "context" + "time" + + antelopeapi "github.com/shufflingpixels/antelope-go/api" + log "github.com/sirupsen/logrus" +) + +// "Clever" way to make sure we only call the api once. +// Store a info pointer outside the returned closure. +// that pointer will live as long as the closure lives. +// and inside the closure we will reference the pointer and only +// call the api if it is nil. +func chainInfoOnce(api *antelopeapi.Client) func() *antelopeapi.Info { + var info *antelopeapi.Info + return func() *antelopeapi.Info { + if info == nil { + log.WithField("api", api.Url).Info("Get chain info from api") + + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + + result, err := api.GetInfo(ctx) + if err != nil { + log.WithError(err).Fatal("Failed to call eos api") + return nil + } + + info = &result + } + return info + } +} diff --git a/cmd/thalos/server.go b/cmd/thalos/server.go index 0fa0c4a..44d0b0d 100644 --- a/cmd/thalos/server.go +++ b/cmd/thalos/server.go @@ -243,33 +243,6 @@ func GetConfig(flags *pflag.FlagSet) (*config.Config, error) { return cfg, nil } -// "Clever" way to make sure we only call the api once. -// Store a info pointer outside the returned closure. -// that pointer will live as long as the closure lives. -// and inside the closure we will reference the pointer and only -// call the api if it is nil. -func chainInfoOnce(api *antelopeapi.Client) func() *antelopeapi.Info { - var info *antelopeapi.Info - return func() *antelopeapi.Info { - if info == nil { - - log.WithField("api", api.Url).Info("Get chain info from api") - - ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) - defer cancel() - - result, err := api.GetInfo(ctx) - if err != nil { - log.WithError(err).Fatal("Failed to call eos api") - return nil - } - - info = &result - } - return info - } -} - func ConnectRedis(conf *config.RedisConfig) (*redis.Client, error) { logEntry := log.WithFields(log.Fields{ "addr": conf.Addr,