Skip to content

Commit

Permalink
rename the check method validate (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Nov 21, 2024
1 parent 6d7cc37 commit a0fa9d7
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions db/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions eth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion migration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c Config) IsEnabled() bool {
return c.Enabled
}

func (Config) Check() error {
func (Config) Validate() error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions pprof/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pprof/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions scheduler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion telemetry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a0fa9d7

Please sign in to comment.