github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/config/types/duration.go (about)

     1  package types
     2  
     3  import "time"
     4  
     5  // Duration is a wrapper type that parses time duration from text.
     6  type Duration struct {
     7  	time.Duration `validate:"required"`
     8  }
     9  
    10  // UnmarshalText unmarshalls time duration from text.
    11  func (d *Duration) UnmarshalText(data []byte) error {
    12  	duration, err := time.ParseDuration(string(data))
    13  	if err != nil {
    14  		return err
    15  	}
    16  	d.Duration = duration
    17  	return nil
    18  }
    19  
    20  // NewDuration returns Duration wrapper
    21  func NewDuration(duration time.Duration) Duration {
    22  	return Duration{time.Duration(duration)}
    23  }