MCPcopy Index your code
hub / github.com/foxcpp/maddy / Duration

Method Duration

framework/config/map.go:202–225  ·  view source on GitHub ↗

Duration maps configuration directive to a time.Duration variable. Directive must be in form 'name duration' where duration is any string accepted by time.ParseDuration. As an additional requirement, result of time.ParseDuration must not be negative. Note that for convenience, if directive does ha

(name string, inheritGlobal, required bool, defaultVal time.Duration, store *time.Duration)

Source from the content-addressed store, hash-verified

200//
201// See Map.Custom for description of arguments.
202func (m *Map) Duration(name string, inheritGlobal, required bool, defaultVal time.Duration, store *time.Duration) {
203 m.Custom(name, inheritGlobal, required, func() (interface{}, error) {
204 return defaultVal, nil
205 }, func(_ *Map, node Node) (interface{}, error) {
206 if len(node.Children) != 0 {
207 return nil, NodeErr(node, "can't declare block here")
208 }
209 if len(node.Args) == 0 {
210 return nil, NodeErr(node, "at least one argument is required")
211 }
212
213 durationStr := strings.Join(node.Args, "")
214 dur, err := time.ParseDuration(durationStr)
215 if err != nil {
216 return nil, NodeErr(node, "%v", err)
217 }
218
219 if dur < 0 {
220 return nil, NodeErr(node, "duration must not be negative")
221 }
222
223 return dur, nil
224 }, store)
225}
226
227func ParseDataSize(s string) (int, error) {
228 if len(s) == 0 {

Callers 5

NewExtResolverFunction · 0.80
ConfigureMethod · 0.80
setConfigMethod · 0.80
GetMethod · 0.80
ConfigureMethod · 0.80

Calls 2

CustomMethod · 0.95
NodeErrFunction · 0.70

Tested by

no test coverage detected