package main

import (
	"fmt"
	"io"
	"os"
	"time"
)

type Sleeper interface {
  Sleep()
}

type SpySleeper struct {
  Calls int
}

func (s *SpySleeper) Sleep() {
  s.Calls++
}

type DefaultSleeper struct{}

func (d *DefaultSleeper) Sleep() {
  time.Sleep(1 * time.Second)
}

const finalWord = "Go!"
const countdownStart = 3

func Countdown(out io.Writer, sleeper Sleeper) {
  for i := countdownStart; i > 0; i-- {
    fmt.Fprintln(out, i)
    sleeper.Sleep()
  }
  fmt.Fprint(out, finalWord)
}

func main() {
  sleeper := &DefaultSleeper{}
  Countdown(os.Stdout, sleeper)
}
