summaryrefslogtreecommitdiff
path: root/pkg/server/sleep.go
blob: fc940799596fd75e858a4d9b4055b3b4fc2a9f52 (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
package server

import (
	"strconv"
	"time"
)

const maxSleep = 10

func init() {
	setHandler(sleep, "sleep")
}

func sleep(r *request) {
	r.expect(1)

	n, err := strconv.Atoi(r.args[0])
	if err != nil || n < 0 {
		r.Printf("invalid time interval '%s'", r.args[0])
		return
	}

	if n > maxSleep {
		r.Printf("no more than %d", maxSleep)
		return
	}

	time.Sleep(time.Duration(n) * time.Second)
}