Simple Tcp Server

Use a simple TCP server to highlight the extra code that can be added to make a process better.

%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart LR
    main("MAIN")

    main --> echoListener("echo server\n:2007")
    echoListener --> echoHandler1("echo client")
    echoListener --> echoHandler2("echo client")

    main --> daytimeListener("daytime server\n:2013")
    daytimeListener --> daytimeHandler1("daytime client")
    daytimeListener --> daytimeHandler2("daytime client")

This server is a TCP server that implements two common TCP services. The echo service (historically on port 7) and the daytime service (historically on port 13). The services will run concurrently. There is a minimal implementation of the server in the Minimal Server page.

  • Refactor into separate packages to provide some isolation.
  • Refactor the listener to make it more general. (DRY, function values)
  • Control-C handling to start cleanup. (signal, channels and context)
  • Add wait groups to allow the server to wait for all services to complete. (sync)
  • Add metrics. (expvar)
  • Add a web server to expose the metrics.
  • Add a logging module to roll logs (lumberjack and vendoring)
  • Signal to roll the logs.
  • Tests
  • Add information during build (Makefile, git, go link commands)
  • Move code to our own module (ex. testing code ioBuffer)