-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e7ac28
commit 89afe2d
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type RefreshInterval time.Duration | ||
|
||
func (self RefreshInterval) String() string { | ||
return time.Duration(self).String() | ||
} | ||
|
||
func (self *RefreshInterval) Set(v interface{}) error { | ||
switch v := v.(type) { | ||
case int: | ||
*self = RefreshInterval(time.Duration(v) * time.Second) | ||
return nil | ||
case string: | ||
i, err := strconv.ParseUint(v, 10, 64) | ||
if err == nil { | ||
*self = RefreshInterval(time.Duration(i) * time.Second) | ||
return nil | ||
} | ||
d, err := time.ParseDuration(v) | ||
if err != nil { | ||
return err | ||
} | ||
ii := RefreshInterval(d) | ||
if ii < MinimumRefreshInterval { | ||
return fmt.Errorf("Refresh interval must be greater than %s", MinimumRefreshInterval) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
*self = ii | ||
return nil | ||
default: | ||
return fmt.Errorf("Invalid refresh interval: %v", v) | ||
} | ||
} | ||
|
||
func (self *RefreshInterval) SetYAML(tag string, v interface{}) bool { | ||
err := self.Set(v) | ||
return err != nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
. "gopkg.in/check.v1" | ||
"gopkg.in/yaml.v1" | ||
) | ||
|
||
type IntervalSuite struct { | ||
} | ||
|
||
var _ = Suite(&IntervalSuite{}) | ||
|
||
type i1 struct { | ||
A RefreshInterval | ||
B RefreshInterval | ||
C RefreshInterval | ||
} | ||
|
||
func (s *IntervalSuite) SetUpSuite(c *C) { | ||
} | ||
|
||
func (s *SyslogSuite) TestInterval(c *C) { | ||
var data = ` | ||
a: 100s | ||
b: 10 | ||
c: '20' | ||
` | ||
v := &i1{} | ||
c.Assert(yaml.Unmarshal([]byte(data), &v), IsNil) | ||
c.Assert(v.A, Equals, RefreshInterval(100*time.Second)) | ||
c.Assert(v.B, Equals, RefreshInterval(10*time.Second)) | ||
c.Assert(v.C, Equals, RefreshInterval(20*time.Second)) | ||
} |
I think this should say "Refresh interval must be greater than or equal to %s"