package main

import (
	"io"
	"log"
	"net"
	"time"
)

type newWriter struct {
	conn io.Writer
}

func (nw newWriter) Write(p []byte) (n int, err error) {
	prefix := []byte("curr time is ")
	prefix = append(prefix, p...)
	n, err = nw.conn.Write(prefix)
	return
}

func handleConn(conn net.Conn) {
	defer conn.Close()

	for {
		_, err := io.WriteString(newWriter{conn}, time.Now().Format("15:04:05\n"))
		if err != nil {
			return
		}
		time.Sleep(1 * time.Second)
	}
}

func main() {
	listener, err := net.Listen("tcp", ":9090")
	if err != nil {
		log.Fatalf("Shit happened %s",err)
	}
	for {
		conn, err := listener.Accept()
		if err != nil {
			log.Printf("Error is %s",err)
			continue
		}
		go handleConn(conn)
	}
}
