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) }