blob: 53c85ea4ba3c35dfa3b62719f22d943a29ffafb3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package server
import (
"strconv"
"time"
"fmt"
)
const maxSleep = 10
func init() {
setHandler(sleep, "sleep")
}
func sleep(r *request) {
if len(r.args) == 0 {
return
}
n, err := strconv.Atoi(r.args[0])
if err != nil || n < 0 {
fmt.Fprintf(r.out, "invalid time interval '%s'", r.args[0])
return
}
if n > maxSleep {
fmt.Fprintf(r.out, "no more than %d", maxSleep)
return
}
time.Sleep(time.Duration(n) * time.Second)
}
|