From a0fa9d7c2952a17c6ea1915bd6b495c2e94040e7 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:03:02 +0800 Subject: [PATCH] rename the check method validate (#3) --- db/config.go | 20 ++++++++++---------- db/config_test.go | 6 +++--- eth/config.go | 8 ++++---- eth/config_test.go | 6 +++--- migration/config.go | 2 +- migration/migration.go | 2 +- pprof/config.go | 6 +++--- pprof/server.go | 2 +- scheduler/config.go | 6 +++--- telemetry/config.go | 8 ++++---- telemetry/server.go | 2 +- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/db/config.go b/db/config.go index dd39e0e..b1628ed 100644 --- a/db/config.go +++ b/db/config.go @@ -68,34 +68,34 @@ func (c Config) MarshalJSON() ([]byte, error) { return json.Marshal(temp) } -func (c Config) Check() error { //nolint:revive // cyclomatic +func (c Config) Validate() error { //nolint:revive // cyclomatic if c.Driver == "" { - return errors.New("check: driver is empty") + return errors.New("driver is empty") } driver, err := GetDriver(c.Driver) if err != nil { - return errors.WithMessage(err, "check: driver is invalid") + return errors.WithMessage(err, "driver is invalid") } if err = driver.ParseSource(c.Source); err != nil { - return errors.WithMessage(err, "check: source is invalid") + return errors.WithMessage(err, "source is invalid") } if c.ConnMaxIdleTime < time.Second || c.ConnMaxIdleTime > time.Hour*24 { - return errors.New("check: conn_max_idle_time is invalid, must between 1 seconds and 24 hours") + return errors.New("conn_max_idle_time is invalid, must between 1 seconds and 24 hours") } if c.ConnMaxLifeTime < time.Second || c.ConnMaxLifeTime > time.Hour*24 { - return errors.New("check: conn_max_life_time is invalid, must between 1 seconds and 24 hours") + return errors.New("conn_max_life_time is invalid, must between 1 seconds and 24 hours") } if c.MaxIdleConn < 1 || c.MaxIdleConn > 500 { - return errors.New("check: max_idle_conn is invalid, must between 1 and 500") + return errors.New("max_idle_conn is invalid, must between 1 and 500") } if c.MaxOpenConn < 1 || c.MaxOpenConn > 500 { - return errors.New("check: max_open_conn is invalid, must between 1 and 500") + return errors.New("max_open_conn is invalid, must between 1 and 500") } if c.MaxOpenConn < c.MaxIdleConn { - return errors.New("check: max_open_conn must greater than max_idle_conn") + return errors.New("max_open_conn must greater than max_idle_conn") } if _, err = parseLogLevel(c.LogLevel); err != nil { - return errors.WithMessage(err, "check: log_level is invalid") + return errors.WithMessage(err, "log_level is invalid") } return nil } diff --git a/db/config_test.go b/db/config_test.go index 42d32c0..e178472 100644 --- a/db/config_test.go +++ b/db/config_test.go @@ -27,12 +27,12 @@ refresh_metric_interval: 15s `, config.String()) } -func (suite *ConfigTestSuite) TestCheck() { +func (suite *ConfigTestSuite) TestValidate() { config := db.NewDefConfig() - suite.Require().NoError(config.Check()) + suite.Require().NoError(config.Validate()) config.Driver = "" - suite.EqualError(config.Check(), "check: driver is empty") + suite.EqualError(config.Validate(), "driver is empty") } func TestConfigTestSuite(t *testing.T) { diff --git a/eth/config.go b/eth/config.go index 16ef897..590ca45 100644 --- a/eth/config.go +++ b/eth/config.go @@ -26,15 +26,15 @@ func (c Config) String() string { return fmt.Sprintf("chainId: %s, rpcUrl: %s", c.ChainId.String(), c.RpcUrl) } -func (c Config) Check() error { +func (c Config) Validate() error { if c.ChainId == nil || c.ChainId.Sign() <= 0 { - return errors.New("check: chain_id is empty") + return errors.New("chain_id is empty") } if c.RpcUrl == "" { - return errors.New("check: rpc_url is empty") + return errors.New("rpc_url is empty") } if c.Timeout <= 0 || c.Timeout > 600*time.Second { - return errors.New("check: timeout is invalid, should be in (0, 600)s") + return errors.New("timeout is invalid, should be in (0, 600)s") } return nil } diff --git a/eth/config_test.go b/eth/config_test.go index b2b4eaa..e19ddbf 100644 --- a/eth/config_test.go +++ b/eth/config_test.go @@ -19,13 +19,13 @@ func (suite *ConfigTestSuite) TestNewDefConfig() { suite.Equal("chainId: 0, rpcUrl: ", config.String()) } -func (suite *ConfigTestSuite) TestCheck() { +func (suite *ConfigTestSuite) TestValidate() { config := eth.NewDefConfig() - suite.Require().EqualError(config.Check(), "check: chain_id is empty") + suite.Require().EqualError(config.Validate(), "chain_id is empty") config.ChainId = big.NewInt(1) config.RpcUrl = "" - suite.Require().EqualError(config.Check(), "check: rpc_url is empty") + suite.Require().EqualError(config.Validate(), "rpc_url is empty") } func TestConfigTestSuite(t *testing.T) { diff --git a/migration/config.go b/migration/config.go index 21c5c3f..c833f80 100644 --- a/migration/config.go +++ b/migration/config.go @@ -26,7 +26,7 @@ func (c Config) IsEnabled() bool { return c.Enabled } -func (Config) Check() error { +func (Config) Validate() error { return nil } diff --git a/migration/migration.go b/migration/migration.go index 7766b86..e57cf9d 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -34,7 +34,7 @@ func (s *Server) Start(context.Context, *errgroup.Group) error { return nil } - if err := s.config.Check(); err != nil { + if err := s.config.Validate(); err != nil { return err } s.logger.Infof("enable migration server") diff --git a/pprof/config.go b/pprof/config.go index 23c50b0..13161ef 100644 --- a/pprof/config.go +++ b/pprof/config.go @@ -24,15 +24,15 @@ func NewDefConfig() Config { } } -func (c Config) Check() error { +func (c Config) Validate() error { if !c.Enabled { return nil } if c.ListenAddr == "" { - return errors.New("check: listen addr is empty") + return errors.New("listen addr is empty") } if c.ReadTimeout < time.Millisecond { - return errors.New("check: read timeout is too small") + return errors.New("read timeout is too small") } return nil } diff --git a/pprof/server.go b/pprof/server.go index 1811ee3..9817e3c 100644 --- a/pprof/server.go +++ b/pprof/server.go @@ -35,7 +35,7 @@ func (s *Server) Start(ctx context.Context, group *errgroup.Group) error { return nil } - if err := s.config.Check(); err != nil { + if err := s.config.Validate(); err != nil { return err } s.logger.Info("init pprof server") diff --git a/scheduler/config.go b/scheduler/config.go index 608f809..4590d93 100644 --- a/scheduler/config.go +++ b/scheduler/config.go @@ -21,15 +21,15 @@ func NewDefConfig() Config { } } -func (c Config) Check() error { +func (c Config) Validate() error { if !c.Enabled { return nil } if c.Interval < 100*time.Millisecond || c.Interval > time.Second*600 { - return errors.Errorf("check: task_interval is invalid, must between 100ms and 600s, got: %s", c.Interval.String()) + return errors.Errorf("task_interval is invalid, must between 100ms and 600s, got: %s", c.Interval.String()) } if c.MaxErrCount <= 0 || c.MaxErrCount > 10000 { - return errors.Errorf("check: task_max_err_count is invalid, must between 1 and 10000, got: %d", c.MaxErrCount) + return errors.Errorf("task_max_err_count is invalid, must between 1 and 10000, got: %d", c.MaxErrCount) } return nil } diff --git a/telemetry/config.go b/telemetry/config.go index ccc84b2..4a57f01 100644 --- a/telemetry/config.go +++ b/telemetry/config.go @@ -56,18 +56,18 @@ func (c Config) IsEnabled() bool { return c.Enabled } -func (c Config) Check() error { +func (c Config) Validate() error { if !c.Enabled { return nil } if c.ListenAddr == "" { - return errors.New("check: listen addr is empty") + return errors.New("listen addr is empty") } if c.ReadTimeout < time.Millisecond { - return errors.New("check: read timeout is too small") + return errors.New("read timeout is too small") } if c.MaxOpenConnections <= 0 { - return errors.New("check: max open connections is negative") + return errors.New("max open connections is negative") } return nil } diff --git a/telemetry/server.go b/telemetry/server.go index 34b2f64..eae0327 100644 --- a/telemetry/server.go +++ b/telemetry/server.go @@ -49,7 +49,7 @@ func (s *Server) Start(ctx context.Context, group *errgroup.Group) error { //nol return nil } - if err := s.config.Check(); err != nil { + if err := s.config.Validate(); err != nil { return err } s.logger.Info("init telemetry server")